移除 data
This commit is contained in:
parent
47a5428d2a
commit
7bd08644ed
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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', '快速登录失败,可能是模块不支持。');
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user