🔒 Update media routes to support private disk and enhance file handling

- 🗂️ Change default filesystem disk from `local` to `private` in configuration
- 📤 Use `Storage::disk` for media download and response functionality
- ⚙️ Refactor download and file response logic for improved security and consistency
This commit is contained in:
HolgerHatGarKeineNode
2026-01-25 19:45:12 +01:00
parent 1391808793
commit 1a73912dd9
2 changed files with 14 additions and 6 deletions

View File

@@ -3,21 +3,29 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Storage;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
Route::redirect('/', '/association/profile');
Route::get('dl/{media}', function (Media $media, Request $request) {
return response()->download($media->getPath(), $media->name);
return Storage::disk($media->disk)->download(
$media->getPathRelativeToRoot(),
$media->file_name
);
})
->name('dl')
->middleware('signed');
Route::get('media/{media}', function (Media $media, Request $request) {
return response()->file($media->getPath(), [
'Content-Type' => $media->mime_type,
'Cache-Control' => 'private, max-age=3600',
]);
return Storage::disk($media->disk)->response(
$media->getPathRelativeToRoot(),
$media->file_name,
[
'Content-Type' => $media->mime_type,
'Cache-Control' => 'private, max-age=3600',
]
);
})
->name('media.signed')
->middleware('signed');