From 1e1df337111dfa998dc8305744934db870969dca Mon Sep 17 00:00:00 2001 From: James Collins Date: Wed, 1 May 2024 18:49:50 +1000 Subject: [PATCH] dont generate variants if it already exists --- app/Http/Controllers/MediaController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/MediaController.php b/app/Http/Controllers/MediaController.php index 4b55669..ac71fe2 100644 --- a/app/Http/Controllers/MediaController.php +++ b/app/Http/Controllers/MediaController.php @@ -206,7 +206,8 @@ class MediaController extends Controller $hash = hash_file('sha256', $file->path()); $storage = Storage::disk('media'); - if(!$storage->exists($hash)) { + $exists = $storage->exists($hash); + if(!$exists) { if($file->storeAs('/', $hash, 'media') === false) { if($request->wantsJson()) { return response()->json([ @@ -230,7 +231,10 @@ class MediaController extends Controller 'hash' => $hash ]); - $media->generateVariants(false); + if(!$exists) { + $media->generateVariants(false); + } + unlink($file->getRealPath()); if($request->wantsJson()) {