From 6e240961fb8f6ad685395133be1e71fe27126620 Mon Sep 17 00:00:00 2001 From: cubemaze Date: Sat, 10 Jun 2023 13:50:42 +0800 Subject: [PATCH] update: code style --- .../Admin/Server/HysteriaController.php | 26 ++------- .../Requests/Admin/ServerHysteriaSave.php | 58 +++++++++++++++++++ .../Requests/Admin/ServerHysteriaUpdate.php | 28 +++++++++ 3 files changed, 91 insertions(+), 21 deletions(-) create mode 100644 app/Http/Requests/Admin/ServerHysteriaSave.php create mode 100755 app/Http/Requests/Admin/ServerHysteriaUpdate.php diff --git a/app/Http/Controllers/Admin/Server/HysteriaController.php b/app/Http/Controllers/Admin/Server/HysteriaController.php index 30948315..4d2b8cee 100644 --- a/app/Http/Controllers/Admin/Server/HysteriaController.php +++ b/app/Http/Controllers/Admin/Server/HysteriaController.php @@ -2,34 +2,18 @@ namespace App\Http\Controllers\Admin\Server; -use App\Http\Requests\Admin\ServerVmessSave; -use App\Http\Requests\Admin\ServerVmessUpdate; +use App\Http\Requests\Admin\ServerHysteriaSave; +use App\Http\Requests\Admin\ServerHysteriaUpdate; use App\Models\ServerHysteria; -use App\Services\ServerService; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Models\ServerVmess; class HysteriaController extends Controller { - public function save(Request $request) + public function save(ServerHysteriaSave $request) { - $params = $request->validate([ - 'show' => '', - 'name' => 'required', - 'group_id' => 'required|array', - 'route_id' => 'nullable|array', - 'parent_id' => 'nullable|integer', - 'host' => 'required', - 'port' => 'required', - 'server_port' => 'required', - 'tags' => 'nullable|array', - 'rate' => 'required|numeric', - 'up_mbps' => 'required|numeric|min:1', - 'down_mbps' => 'required|numeric|min:1', - 'server_name' => 'nullable', - 'insecure' => 'required|in:0,1' - ]); + $params = $request->validate(); if ($request->input('id')) { $server = ServerHysteria::find($request->input('id')); @@ -68,7 +52,7 @@ class HysteriaController extends Controller ]); } - public function update(Request $request) + public function update(ServerHysteriaUpdate $request) { $request->validate([ 'show' => 'in:0,1' diff --git a/app/Http/Requests/Admin/ServerHysteriaSave.php b/app/Http/Requests/Admin/ServerHysteriaSave.php new file mode 100644 index 00000000..eb0727aa --- /dev/null +++ b/app/Http/Requests/Admin/ServerHysteriaSave.php @@ -0,0 +1,58 @@ + '', + 'name' => 'required', + 'group_id' => 'required|array', + 'route_id' => 'nullable|array', + 'parent_id' => 'nullable|integer', + 'host' => 'required', + 'port' => 'required', + 'server_port' => 'required', + 'tags' => 'nullable|array', + 'rate' => 'required|numeric', + 'up_mbps' => 'required|numeric|min:1', + 'down_mbps' => 'required|numeric|min:1', + 'server_name' => 'nullable', + 'insecure' => 'required|in:0,1' + ]; + } + + public function messages() + { + return [ + 'name.required' => '节点名称不能为空', + 'group_id.required' => '权限组不能为空', + 'group_id.array' => '权限组格式不正确', + 'route_id.array' => '路由组格式不正确', + 'parent_id.integer' => '父节点格式不正确', + 'host.required' => '节点地址不能为空', + 'port.required' => '连接端口不能为空', + 'server_port.required' => '后端服务端口不能为空', + 'tags.array' => '标签格式不正确', + 'rate.required' => '倍率不能为空', + 'rate.numeric' => '倍率格式不正确', + 'up_mbps.required' => '上传速度不能为空', + 'up_mbps.numeric' => '上传速度格式不正确', + 'up_mbps.min' => '上传速度必须大于0', + 'down_mbps.required' => '下载速度不能为空', + 'down_mbps.numeric' => '下载速度格式不正确', + 'down_mbps.min' => '下载速度必须大于0', + 'insecure.required' => '安全性不能为空', + 'insecure.in' => '安全性格式不正确', + ]; + } +} diff --git a/app/Http/Requests/Admin/ServerHysteriaUpdate.php b/app/Http/Requests/Admin/ServerHysteriaUpdate.php new file mode 100755 index 00000000..eaab385b --- /dev/null +++ b/app/Http/Requests/Admin/ServerHysteriaUpdate.php @@ -0,0 +1,28 @@ + 'in:0,1' + ]; + } + + public function messages() + { + return [ + 'show.in' => '显示状态格式不正确' + ]; + } +}