mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-07 04:59:36 +00:00
- Optimize Blade JavaScript code. - Refactored multiple admin controllers for improved validation, error handling, and query efficiency. - Added ProxyConfig trait to centralize proxy configuration options. - Updated NodeStatusDetection to use model relationships for heartbeat checks. - Improved category, label, and country management logic and error logging. - Added new Blade components for admin UI and updated language files and assets for better localization and frontend support. - Bug fixed & introduced more bug :)
74 lines
3.2 KiB
PHP
74 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Config;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\SsConfig;
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Log;
|
|
use Validator;
|
|
|
|
class SsConfigController extends Controller
|
|
{
|
|
public function store(Request $request): JsonResponse
|
|
{ // 添加SS配置
|
|
$validator = Validator::make($request->all(), [
|
|
'name' => 'required|string|unique:ss_config,name',
|
|
'type' => 'required|numeric|between:1,3',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
return response()->json(['status' => 'fail', 'message' => $validator->errors()->all()]);
|
|
}
|
|
|
|
try {
|
|
if (SsConfig::create($validator->validated())) {
|
|
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.add')])]);
|
|
}
|
|
} catch (Exception $e) {
|
|
Log::error(trans('common.error_action_item', ['action' => trans('common.add'), 'attribute' => trans('user.node.info')]).': '.$e->getMessage());
|
|
|
|
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.add')]).', '.$e->getMessage()]);
|
|
}
|
|
|
|
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.add')])]);
|
|
}
|
|
|
|
public function update(SsConfig $ss): JsonResponse
|
|
{ // 设置SS默认配置
|
|
try {
|
|
if ($ss->setDefault()) {
|
|
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.edit')])]);
|
|
}
|
|
} catch (Exception $e) {
|
|
Log::error(trans('common.error_action_item', ['action' => trans('common.edit'), 'attribute' => trans('user.node.info')]).': '.$e->getMessage());
|
|
|
|
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.edit')]).', '.$e->getMessage()]);
|
|
}
|
|
|
|
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.edit')])]);
|
|
}
|
|
|
|
public function destroy(SsConfig $ss): JsonResponse
|
|
{ // 删除SS配置
|
|
// 检查是否为默认配置
|
|
if ($ss->is_default) {
|
|
return response()->json(['status' => 'fail', 'message' => trans('admin.setting.common.config_default_cannot_delete')]);
|
|
}
|
|
|
|
try {
|
|
if ($ss->delete()) {
|
|
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.delete')])]);
|
|
}
|
|
} catch (Exception $e) {
|
|
Log::error(trans('common.error_action_item', ['action' => trans('common.delete'), 'attribute' => trans('user.node.info')]).': '.$e->getMessage());
|
|
|
|
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.delete')]).', '.$e->getMessage()]);
|
|
}
|
|
|
|
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.delete')])]);
|
|
}
|
|
}
|