perf: 图片容错处理

This commit is contained in:
kuaifan 2024-12-12 22:36:25 +08:00
parent 520d2a0e20
commit 29bc009c07
2 changed files with 15 additions and 2 deletions

View File

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

View File

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