修复 HTTP 请求

This commit is contained in:
iVampireSP.com 2023-01-21 17:24:42 +08:00
parent 58f7a4a7ad
commit 0fa6d1e2a6
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 11 additions and 8 deletions

View File

@ -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

View File

@ -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);
}