From 29bc009c07ee3abf1aaa3bee81d2b4c3e0426d4f Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 12 Dec 2024 22:36:25 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=9B=BE=E7=89=87=E5=AE=B9=E9=94=99?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Exceptions/Handler.php | 13 +++++++++++++ routes/web.php | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 582f23e5e..b423bc0a7 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -223,6 +223,19 @@ class Handler extends ExceptionHandler } catch (\ImagickException) { } } + // 容错处理 + $patternFault = '/^(images\/.*\.(png|jpg|jpeg))\/crop\/([^\/]+)$/'; + $matchesFault = null; + if (preg_match($patternFault, $path, $matchesFault)) { + $file = public_path($matchesFault[1]); + if (!file_exists($file)) { + $file = public_path('images/other/imgerr.jpg'); + } + if (file_exists($file)) { + return response()->file($file); + } + } + return null; } } diff --git a/routes/web.php b/routes/web.php index 42dba4179..403dfb66b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -69,6 +69,6 @@ Route::middleware(['webapi'])->group(function () { Route::any('/{method}', IndexController::class); Route::any('/{method}/{action}', IndexController::class); Route::any('/{method}/{action}/{child}', IndexController::class); - Route::any('/{method}/{action}/{child}/{n}', IndexController::class)->where('method', '^(?!uploads).*'); - Route::any('/{method}/{action}/{child}/{n}/{c}', IndexController::class)->where('method', '^(?!uploads).*'); + Route::any('/{method}/{action}/{child}/{n}', IndexController::class)->where('method', '^(?!(uploads|images)).*'); + Route::any('/{method}/{action}/{child}/{n}/{c}', IndexController::class)->where('method', '^(?!(uploads|images)).*'); });