Browse Source

Update MediaController, fix redirect bug

Daniel Supernault 5 months ago
parent
commit
dc4e683f0a
1 changed files with 11 additions and 4 deletions
  1. 11 4
      app/Http/Controllers/MediaController.php

+ 11 - 4
app/Http/Controllers/MediaController.php

@@ -9,7 +9,6 @@ class MediaController extends Controller
 {
     public function index(Request $request)
     {
-        //return view('settings.drive.index');
         abort(404);
     }
 
@@ -20,13 +19,21 @@ class MediaController extends Controller
 
     public function fallbackRedirect(Request $request, $pid, $mhash, $uhash, $f)
     {
-        abort_if(! (bool) config_cache('pixelfed.cloud_storage'), 404);
+        if (! (bool) config_cache('pixelfed.cloud_storage')) {
+            return redirect('/storage/no-preview.png', 302);
+        }
+
         $path = 'public/m/_v2/'.$pid.'/'.$mhash.'/'.$uhash.'/'.$f;
+
         $media = Media::whereProfileId($pid)
             ->whereMediaPath($path)
             ->whereNotNull('cdn_url')
-            ->firstOrFail();
+            ->first();
+
+        if (! $media) {
+            return redirect('/storage/no-preview.png', 302);
+        }
 
-        return redirect()->away($media->cdn_url);
+        return redirect()->away($media->cdn_url, 302);
     }
 }