From 0fa6d1e2a6d48b18af3c6f8bb1647e43a3680cc2 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Sat, 21 Jan 2023 17:24:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20HTTP=20=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Module/ModuleController.php | 3 ++- app/Models/Module.php | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Module/ModuleController.php b/app/Http/Controllers/Module/ModuleController.php index de467b6..0068527 100644 --- a/app/Http/Controllers/Module/ModuleController.php +++ b/app/Http/Controllers/Module/ModuleController.php @@ -37,7 +37,8 @@ private function fixPath(Request $request, Module $module, $prefix): string { $path = substr($request->path(), strlen("/$prefix/modules/$module->id")); - return preg_replace('/[^a-zA-Z0-9\/]/', '', $path); + // 去除 非法字符 + return preg_replace('/[^a-zA-Z0-9\/\-]/', '', $path); } public function exportCall(Request $request, Module $module): Response|JsonResponse diff --git a/app/Models/Module.php b/app/Models/Module.php index d325d37..2236c69 100644 --- a/app/Models/Module.php +++ b/app/Models/Module.php @@ -117,18 +117,20 @@ public function baseRequest($method, $path, $requests = []): array { $user = auth('sanctum')->user(); + $http = $this->http(); if ($user) { - $this->http()->withHeaders([ + $http = $http->withHeaders([ 'X-User-Id' => $user->id, ]); - $requests['user_id'] = $user->id; - if ($method == 'post') { - // add user to requests - $requests['user'] = $user; - } + + // $requests['user_id'] = $user->id; + // if ($method == 'post') { + // // add user to requests + // $requests['user'] = $user; + // } } - $response = $this->http()->{$method}($path, $requests); + $response = $http->{$method}($path, $requests); return $this->getResponse($response); }