From 4973cb46118eed5b383e26696a367ba05392641a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 22 May 2023 18:10:55 -0600 Subject: [PATCH 1/2] Update MediaController, add fallback for local files that are later stored on S3 but still are referenced in cached objects remotely --- app/Http/Controllers/MediaController.php | 20 ++++++++++++-------- routes/web.php | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/MediaController.php b/app/Http/Controllers/MediaController.php index 4416837cc..b10e75795 100644 --- a/app/Http/Controllers/MediaController.php +++ b/app/Http/Controllers/MediaController.php @@ -3,18 +3,10 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use Auth, Storage, URL; use App\Media; -use Image as Intervention; -use App\Jobs\ImageOptimizePipeline\ImageOptimize; class MediaController extends Controller { - public function __construct() - { - $this->middleware('auth'); - } - public function index(Request $request) { //return view('settings.drive.index'); @@ -24,4 +16,16 @@ class MediaController extends Controller { abort(400, 'Endpoint deprecated'); } + + public function fallbackRedirect(Request $request, $pid, $mhash, $uhash, $f) + { + abort_if(!config_cache('pixelfed.cloud_storage'), 404); + $path = 'public/m/_v2/' . $pid . '/' . $mhash . '/' . $uhash . '/' . $f; + $media = Media::whereProfileId($pid) + ->whereMediaPath($path) + ->whereNotNull('cdn_url') + ->firstOrFail(); + + return redirect()->away($media->cdn_url); + } } diff --git a/routes/web.php b/routes/web.php index 7a9352201..3c84ea808 100644 --- a/routes/web.php +++ b/routes/web.php @@ -616,6 +616,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('auth/invite/a/{code}', 'AdminInviteController@index'); Route::post('api/v1.1/auth/invite/admin/re', 'AdminInviteController@apiRegister')->middleware('throttle:5,1440'); + Route::get('storage/m/_v2/{pid}/{mhash}/{uhash}/{f}', 'MediaController@fallbackRedirect'); Route::get('stories/{username}', 'ProfileController@stories'); Route::get('p/{id}', 'StatusController@shortcodeRedirect'); Route::get('c/{collection}', 'CollectionController@show'); From f452509e17479c5973ba97e6952d81503dd62c48 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 22 May 2023 18:12:41 -0600 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b35a7e811..48cc7b7c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ - Update admin moderation logic, only re-add top level posts ([c6ffda96](https://github.com/pixelfed/pixelfed/commit/c6ffda96)) - Update admin dashboard, add mass account deletes ([b8426cce](https://github.com/pixelfed/pixelfed/commit/b8426cce)) - Update scheduler, fix S3 media garbage collection not being executed when cloud storage is enabled via dashboard without .env/config being enabled ([adb070f1](https://github.com/pixelfed/pixelfed/commit/adb070f1)) +- Update MediaController, add fallback for local files that are later stored on S3 but still are referenced in cached objects remotely ([4973cb46](https://github.com/pixelfed/pixelfed/commit/4973cb46)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.6 (2023-05-03)](https://github.com/pixelfed/pixelfed/compare/v0.11.5...v0.11.6)