diff --git a/app/Helpers/ApiResponse.php b/app/Helpers/ApiResponse.php index c2f27f3..240fa64 100644 --- a/app/Helpers/ApiResponse.php +++ b/app/Helpers/ApiResponse.php @@ -10,10 +10,6 @@ trait ApiResponse // RESTful API response public function moduleResponse($response, int $status = 200): JsonResponse { - if (isset($response['data'])) { - $response = $response['data']; - } - return match ($status) { 200 => $this->success($response), 201 => $this->created($response), @@ -26,7 +22,7 @@ public function moduleResponse($response, int $status = 200): JsonResponse 429 => $this->tooManyRequests(), 500 => $this->serverError(), - default => response()->json($response['data'] ?? $response, $status), + default => response()->json($response, $status), }; } @@ -42,31 +38,6 @@ public function error($message = '', $code = 400): JsonResponse public function apiResponse($data = [], $status = 200): JsonResponse { - // // if data is paginated, return paginated data - // if ($data instanceof Paginator) { - // $data = $data->toArray(); - // $data['data'] = $data['data'] ?? []; - // $data['meta'] = [ - // 'per_page' => $data['per_page'] ?? 0, - // 'current_page' => $data['current_page'] ?? 0, - // 'from' => $data['from'] ?? 0, - // 'to' => $data['to'] ?? 0, - // ]; - // $data['paginate'] = 1; - // } else { - // $data = [ - // 'data' => $data, - // ]; - // } - // - // $data['status'] = $status; - // - // if ($status >= 200 && $status <= 299) { - // $data['success'] = 1; - // } else { - // $data['success'] = 0; - // } - return response()->json($data, $status)->setEncodingOptions(JSON_UNESCAPED_UNICODE); } diff --git a/app/Http/Controllers/Admin/ModuleController.php b/app/Http/Controllers/Admin/ModuleController.php index 3dc0ca2..80a0045 100644 --- a/app/Http/Controllers/Admin/ModuleController.php +++ b/app/Http/Controllers/Admin/ModuleController.php @@ -193,7 +193,7 @@ public function fast_login(Module $module): View|RedirectResponse $resp = $module->baseRequest('post', 'fast-login', []); if ($resp['success']) { - $resp = $resp['json']['data']; + $resp = $resp['json']; return view('admin.modules.login', compact('module', 'resp')); } else { return redirect()->route('admin.modules.show', $module)->with('error', '快速登录失败,可能是模块不支持。'); diff --git a/app/Jobs/Module/FetchModule.php b/app/Jobs/Module/FetchModule.php index 6cecf64..210ff2d 100644 --- a/app/Jobs/Module/FetchModule.php +++ b/app/Jobs/Module/FetchModule.php @@ -65,7 +65,7 @@ public function handle() $json = $response->json(); - if (isset($json['data']['servers']) && is_array($json['data']['servers'])) { + if (isset($json['servers']) && is_array($json['servers'])) { // 只保留 name, status, meta $servers = array_merge($servers, array_map(function ($server) use ($module) { return [ @@ -79,7 +79,7 @@ public function handle() 'name' => $module->name, ] ]; - }, $json['data']['servers'])); + }, $json['servers'])); broadcast(new ServerEvent($servers)); } diff --git a/app/Jobs/Module/PushHost.php b/app/Jobs/Module/PushHost.php index 56345d4..918f51c 100644 --- a/app/Jobs/Module/PushHost.php +++ b/app/Jobs/Module/PushHost.php @@ -47,8 +47,8 @@ public function handle() $response_json = $response->json(); // 检测是否有价格 - if (isset($response_json['data']['price'])) { - $host->price = $response_json['data']['price']; + if (isset($response_json['price'])) { + $host->price = $response_json['price']; } else { $host->status = 'error'; }