From e0eac8f703624dea0bf223d94158a567f2797df4 Mon Sep 17 00:00:00 2001 From: xboard Date: Sun, 19 Nov 2023 09:54:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=BC=E5=AE=B9V2bx=20=E7=9A=84Hyste?= =?UTF-8?q?ria2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../V1/Server/UniProxyController.php | 2 +- app/Http/Middleware/Server.php | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/V1/Server/UniProxyController.php b/app/Http/Controllers/V1/Server/UniProxyController.php index e6e324b..e9baf1e 100644 --- a/app/Http/Controllers/V1/Server/UniProxyController.php +++ b/app/Http/Controllers/V1/Server/UniProxyController.php @@ -22,7 +22,7 @@ class UniProxyController extends Controller { $this->serverService = $serverService; $this->nodeId = $request->input('node_id'); - $this->nodeType = $request->input('node_type') === 'v2ray' ? 'vmess' : $request->input('node_type'); + $this->nodeType = $request->input('node_type'); $this->nodeInfo = $this->serverService->getServer($this->nodeId, $this->nodeType); if(!$this->nodeInfo) { Log::channel("daily")->info("$this->nodeId $this->nodeType $this->nodeInfo"); diff --git a/app/Http/Middleware/Server.php b/app/Http/Middleware/Server.php index 9b4c32d..90ce2ec 100644 --- a/app/Http/Middleware/Server.php +++ b/app/Http/Middleware/Server.php @@ -16,22 +16,31 @@ class Server */ public function handle(Request $request, Closure $next) { + // alias + $aliasTypes = [ + 'v2ray' => 'vmess', + 'hysteria2' => 'hysteria' + ]; $request->validate([ 'token' => ['required','string',function ($attribute, $value, $fail) { if ($value != admin_setting('server_token')) { $fail("The $attribute is error."); } }], + 'node_id' => 'required', 'node_type' => [ 'nullable', 'string', - 'regex:/^(?i)(hysteria|vless|trojan|vmess|v2ray|tuic|shadowsocks|shadowsocks-plugin)$/', - function ($attribute, $value, $fail) { + 'regex:/^(?i)(hysteria|hysteria2|vless|trojan|vmess|v2ray|tuic|shadowsocks|shadowsocks-plugin)$/', + function ($attribute, $value, $fail)use($aliasTypes) { // 将值转换为小写 request()->merge([$attribute => strtolower($value)]); + // 类别别名 + if (in_array($value, array_keys($aliasTypes))){ + request()->merge([$attribute => $aliasTypes[$value]]); + } }, - ], - 'node_id' => 'required' + ] ]); return $next($request);