优化 远程调用代码

This commit is contained in:
iVampireSP.com 2022-11-24 19:59:32 +08:00
parent 1206b9c92f
commit 7cd2928e45
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -19,9 +19,7 @@ public function index()
public function call(Request $request, Module $module)
{
$path = request()->path();
$path = substr($path, strlen('/api/modules/' . $module->id));
$path = preg_replace('/[^a-zA-Z0-9\/]/', '', $path);
$path = $this->fixPath($request, $module, 'api');
$method = Str::lower($request->method());
@ -45,11 +43,7 @@ public function call(Request $request, Module $module)
public function exportCall(Request $request, Module $module): Response|JsonResponse
{
$path = request()->path();
$path = substr($path, strlen('/modules/modules/' . $module->id));
$path = preg_replace('/[^a-zA-Z0-9\/]/', '', $path);
$path = $this->fixPath($request, $module, 'modules');
$method = Str::lower($request->method());
$response = $module->moduleRequest($method, $path, $request->all());
@ -60,4 +54,10 @@ public function exportCall(Request $request, Module $module): Response|JsonRespo
return $this->moduleResponse($response['json'], $response['status']);
}
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);
}
}