fix: 修复文档转换与预览链路中的图片、文件名和错误处理问题
This commit is contained in:
@@ -98,18 +98,24 @@ Route::middleware(['auth'])->group(function () {
|
||||
});
|
||||
|
||||
// 提供 markdown 目录中 media 文件的访问(需要认证)
|
||||
// 路径格式: /markdown/{path}/media/{filename}
|
||||
// 其中 path 可以是: 2025/12/04/{uuid} 或 {uuid}
|
||||
Route::middleware(['auth'])->get('/markdown/{path}/media/{filename}', function ($path, $filename) {
|
||||
// 构建完整路径
|
||||
$fullPath = $path . '/media/' . $filename;
|
||||
|
||||
if (!Storage::disk('markdown')->exists($fullPath)) {
|
||||
// 路径格式: /markdown-media/{path}
|
||||
Route::middleware(['auth'])->get('/markdown-media/{path}', function ($path) {
|
||||
$path = trim((string) $path, '/');
|
||||
|
||||
if ($path === '' || str_contains($path, '../')) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$file = Storage::disk('markdown')->get($fullPath);
|
||||
$mimeType = Storage::disk('markdown')->mimeType($fullPath);
|
||||
|
||||
|
||||
if (!Storage::disk('markdown')->exists($path)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$mimeType = Storage::disk('markdown')->mimeType($path);
|
||||
if (!is_string($mimeType) || !str_starts_with($mimeType, 'image/')) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$file = Storage::disk('markdown')->get($path);
|
||||
|
||||
return response($file, 200)->header('Content-Type', $mimeType);
|
||||
})->where('path', '.*')->where('filename', '[^/]+')->name('markdown.media');
|
||||
})->where('path', '.*')->name('markdown.media');
|
||||
|
||||
Reference in New Issue
Block a user