From cb92bc90f2577ad7497fa2033c913730c4133ff0 Mon Sep 17 00:00:00 2001 From: BrettonYe <867057410@qq.com> Date: Mon, 16 Mar 2026 23:58:59 +0800 Subject: [PATCH] Fixed proxy info display incorrect --- .../Controllers/Api/Client/ClientController.php | 11 ++++++----- app/Http/Controllers/User/NodeController.php | 4 ++-- app/Http/Controllers/User/SubscribeController.php | 14 +++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Api/Client/ClientController.php b/app/Http/Controllers/Api/Client/ClientController.php index e9ba4806..2f65e8d7 100644 --- a/app/Http/Controllers/Api/Client/ClientController.php +++ b/app/Http/Controllers/Api/Client/ClientController.php @@ -176,11 +176,11 @@ class ClientController extends Controller return $this->succeed(null, null, [200, trans('user.home.attendance.success', ['data' => formatBytes($traffic)])]); } - public function proxyCheck(Request $request, ProxyService $proxyService): JsonResponse + public function proxyCheck(Request $request): JsonResponse { $md5 = $request->get('md5', ''); - $proxy = $proxyService->buildClientConfig('clash'); + $proxy = (new ProxyService())->buildClientConfig('clash'); if (strtolower(md5(json_encode($proxy))) === strtolower($md5)) { return $this->succeed(false); } @@ -188,16 +188,17 @@ class ClientController extends Controller return $this->succeed(true, ['md5' => strtolower(md5(json_encode($proxy)))]); } - public function downloadProxies(Request $request, ProxyService $proxyService): string + public function downloadProxies(Request $request): string { $flag = strtolower($request->input('flag') ?? ($request->userAgent() ?? '')); - return $proxyService->buildClientConfig($flag === 'v2rayng' ? 'v2rayng' : 'clash', $request->input('type')); + return (new ProxyService())->buildClientConfig($flag === 'v2rayng' ? 'v2rayng' : 'clash', $request->input('type')); } - public function getProxyList(ProxyService $proxyService): JsonResponse + public function getProxyList(): JsonResponse { $servers = []; + $proxyService = new ProxyService(); foreach ($proxyService->fetchAvailableNodes(null, false)->load('latestOnlineLog') as $node) { $server = $proxyService->generateNodeConfig($node); if ($server['type'] === 'shadowsocks' || $server['type'] === 'shadowsocksr') { diff --git a/app/Http/Controllers/User/NodeController.php b/app/Http/Controllers/User/NodeController.php index 7c507062..a837cf10 100644 --- a/app/Http/Controllers/User/NodeController.php +++ b/app/Http/Controllers/User/NodeController.php @@ -27,13 +27,13 @@ class NodeController extends Controller return view('user.services', compact('nodesGeo', 'nodes')); } - public function show(Request $request, Node $node, ProxyService $proxyServer): JsonResponse + public function show(Request $request, Node $node): JsonResponse { // 节点详细信息 // 验证用户是否有权限访问该节点 if (! auth()->user()->nodes()->where('node.id', $node->id)->exists()) { return response()->json(['status' => 'fail', 'message' => trans('http-statuses.401')]); } - return response()->json(['status' => 'success', 'data' => $proxyServer->getUserProxyConfig($node, $request->input('type') !== 'text')]); + return response()->json(['status' => 'success', 'data' => (new ProxyService())->getUserProxyConfig($node, $request->input('type') !== 'text')]); } } diff --git a/app/Http/Controllers/User/SubscribeController.php b/app/Http/Controllers/User/SubscribeController.php index e30bd75e..41180be8 100644 --- a/app/Http/Controllers/User/SubscribeController.php +++ b/app/Http/Controllers/User/SubscribeController.php @@ -18,11 +18,11 @@ class SubscribeController extends Controller private ?string $target; - private ProxyService $proxyServer; + private ProxyService $proxyService; - public function __construct(ProxyService $proxyServer) + public function __construct(ProxyService $proxyService) { - $this->proxyServer = $proxyServer; + $this->proxyService = $proxyService; } public function index(Request $request, string $code): RedirectResponse|View @@ -100,7 +100,7 @@ class SubscribeController extends Controller } // 设置用户并更新订阅信息 - $this->proxyServer->setUser($user); + $this->proxyService->setUser($user); $subscribe->increment('times'); // 更新访问次数 // 记录订阅日志 @@ -110,15 +110,15 @@ class SubscribeController extends Controller ], JSON_THROW_ON_ERROR)); // 返回订阅内容 - return $this->proxyServer->buildClientConfig($this->target, self::$subType); + return $this->proxyService->buildClientConfig($this->target, self::$subType); } private function failed(string $text): string { // 抛出错误的节点信息,用于兼容防止客户端订阅失败 - $this->proxyServer->failedProxyReturn($text, self::$subType ?? 0); + $this->proxyService->failedProxyReturn($text, self::$subType ?? 0); // 返回错误配置而不是空字符串,以确保客户端收到有效内容 - return $this->proxyServer->buildClientConfig($this->target, self::$subType); + return $this->proxyService->buildClientConfig($this->target, self::$subType); } private function subscribeLog(int $subscribeId, ?string $ip, string $headers): void