Update MediaController, add fallback for local files that are later stored on S3 but still are referenced in cached objects remotely

This commit is contained in:
Daniel Supernault 2023-05-22 18:10:55 -06:00
parent a1ab88a8ca
commit 4973cb4611
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 13 additions and 8 deletions

View file

@ -3,18 +3,10 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Auth, Storage, URL;
use App\Media; use App\Media;
use Image as Intervention;
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
class MediaController extends Controller class MediaController extends Controller
{ {
public function __construct()
{
$this->middleware('auth');
}
public function index(Request $request) public function index(Request $request)
{ {
//return view('settings.drive.index'); //return view('settings.drive.index');
@ -24,4 +16,16 @@ class MediaController extends Controller
{ {
abort(400, 'Endpoint deprecated'); 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);
}
} }

View file

@ -616,6 +616,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('auth/invite/a/{code}', 'AdminInviteController@index'); Route::get('auth/invite/a/{code}', 'AdminInviteController@index');
Route::post('api/v1.1/auth/invite/admin/re', 'AdminInviteController@apiRegister')->middleware('throttle:5,1440'); 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('stories/{username}', 'ProfileController@stories');
Route::get('p/{id}', 'StatusController@shortcodeRedirect'); Route::get('p/{id}', 'StatusController@shortcodeRedirect');
Route::get('c/{collection}', 'CollectionController@show'); Route::get('c/{collection}', 'CollectionController@show');