From b2ac536112256ec74fbc141641d9f7802fae44ce Mon Sep 17 00:00:00 2001 From: Mohamed Slimani Date: Tue, 30 May 2023 12:43:55 +0100 Subject: [PATCH 1/6] add s3 support --- public/js/script.js | 4 ++-- src/Controllers/DownloadController.php | 17 +++++++++++++++-- src/LfmStorageRepository.php | 11 ++++++++++- src/config/lfm.php | 2 ++ src/views/crop.blade.php | 2 +- src/views/resize.blade.php | 4 ++-- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/public/js/script.js b/public/js/script.js index 2a2b49c9..082fca05 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -450,7 +450,7 @@ function loadItems(page) { }); if (item.thumb_url) { - var image = $('
').css('background-image', 'url("' + item.thumb_url + '?timestamp=' + item.time + '")'); + var image = $('
').css('background-image', 'url("' + item.thumb_url + '")'); } else { var icon = $('
').addClass('ico'); var image = $('
').addClass('mime-icon ico-' + item.icon).append(icon); @@ -591,7 +591,7 @@ function preview(items) { .addClass(index === 0 ? 'active' : ''); if (item.thumb_url) { - carouselItem.find('.carousel-image').css('background-image', 'url(\'' + item.url + '?timestamp=' + item.time + '\')'); + carouselItem.find('.carousel-image').css('background-image', 'url(\'' + item.url + '\')'); } else { carouselItem.find('.carousel-image').css('width', '50vh').append($('
').addClass('mime-icon ico-' + item.icon)); } diff --git a/src/Controllers/DownloadController.php b/src/Controllers/DownloadController.php index cf3391b2..a7594eaf 100644 --- a/src/Controllers/DownloadController.php +++ b/src/Controllers/DownloadController.php @@ -8,12 +8,25 @@ class DownloadController extends LfmController { public function getDownload() { - $file = $this->lfm->setName(request('file')); + $file_name = request('file'); + $file = $this->lfm->setName($file_name); if (!Storage::disk($this->helper->config('disk'))->exists($file->path('storage'))) { abort(404); } - return response()->download($file->path('absolute')); + $disk = Storage::disk($this->helper->config('disk')); + $config = $disk->getConfig(); + + if (key_exists('driver', $config) && $config['driver'] == 's3') { + $duration = $this->helper->config('temporary_url_duration'); + return response()->streamDownload( + function () { + echo file_get_contents($disk->temporaryUrl($file->path('storage'), now()->addMinutes($duration))); + }, $file_name, + ); + } else { + return response()->download($file->path('absolute')); + } } } diff --git a/src/LfmStorageRepository.php b/src/LfmStorageRepository.php index cce407fa..46090cf4 100644 --- a/src/LfmStorageRepository.php +++ b/src/LfmStorageRepository.php @@ -43,7 +43,16 @@ public function save($file) public function url($path) { - return $this->disk->url($path); + $config = $this->disk->getConfig(); + + if (key_exists('driver', $config) && $config['driver'] == 's3') + + $duration = $this->helper->config('s3.temporary_url_expiration'); + return $this->disk->temporaryUrl($path, now()->addMinutes($duration)); + + else { + return $this->disk->url($path); + } } public function makeDirectory() diff --git a/src/config/lfm.php b/src/config/lfm.php index 5c418126..8b83e666 100644 --- a/src/config/lfm.php +++ b/src/config/lfm.php @@ -96,6 +96,8 @@ 'disk' => 'public', + 'temporary_url_duration' => 30, + 'rename_file' => false, 'rename_duplicates' => false, diff --git a/src/views/crop.blade.php b/src/views/crop.blade.php index 094ebd25..492b3f60 100644 --- a/src/views/crop.blade.php +++ b/src/views/crop.blade.php @@ -1,7 +1,7 @@
- +
diff --git a/src/views/resize.blade.php b/src/views/resize.blade.php index f4134f75..1f8563b4 100644 --- a/src/views/resize.blade.php +++ b/src/views/resize.blade.php @@ -19,9 +19,9 @@
- +
-
+
From eeb8232f67ea4382f44f6099185d7e7c6f6eb223 Mon Sep 17 00:00:00 2001 From: Mohamed Slimani Date: Tue, 30 May 2023 12:47:56 +0100 Subject: [PATCH 2/6] fix typo --- src/LfmStorageRepository.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/LfmStorageRepository.php b/src/LfmStorageRepository.php index 46090cf4..5cf79d0b 100644 --- a/src/LfmStorageRepository.php +++ b/src/LfmStorageRepository.php @@ -45,12 +45,10 @@ public function url($path) { $config = $this->disk->getConfig(); - if (key_exists('driver', $config) && $config['driver'] == 's3') - - $duration = $this->helper->config('s3.temporary_url_expiration'); + if (key_exists('driver', $config) && $config['driver'] == 's3') { + $duration = $this->helper->config('temporary_url_duration'); return $this->disk->temporaryUrl($path, now()->addMinutes($duration)); - - else { + } else { return $this->disk->url($path); } } From 9ada42eb8292881abf88ab079f4845c84914fcdf Mon Sep 17 00:00:00 2001 From: Mohamed Slimani Date: Tue, 30 May 2023 12:50:05 +0100 Subject: [PATCH 3/6] fix typo --- src/Controllers/DownloadController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Controllers/DownloadController.php b/src/Controllers/DownloadController.php index a7594eaf..d6ec98c0 100644 --- a/src/Controllers/DownloadController.php +++ b/src/Controllers/DownloadController.php @@ -23,8 +23,7 @@ public function getDownload() return response()->streamDownload( function () { echo file_get_contents($disk->temporaryUrl($file->path('storage'), now()->addMinutes($duration))); - }, $file_name, - ); + }, $file_name); } else { return response()->download($file->path('absolute')); } From 488c59949737c0d0b6ec40abfec01f13a61d4277 Mon Sep 17 00:00:00 2001 From: Mohamed Slimani Date: Tue, 30 May 2023 12:50:58 +0100 Subject: [PATCH 4/6] fix style --- src/Controllers/DownloadController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controllers/DownloadController.php b/src/Controllers/DownloadController.php index d6ec98c0..5f5ce636 100644 --- a/src/Controllers/DownloadController.php +++ b/src/Controllers/DownloadController.php @@ -23,7 +23,8 @@ public function getDownload() return response()->streamDownload( function () { echo file_get_contents($disk->temporaryUrl($file->path('storage'), now()->addMinutes($duration))); - }, $file_name); + }, $file_name + ); } else { return response()->download($file->path('absolute')); } From 06efd05517b47802bb163de1c5b2bf4738abdf20 Mon Sep 17 00:00:00 2001 From: Mohamed Slimani Date: Tue, 30 May 2023 12:52:31 +0100 Subject: [PATCH 5/6] fix style --- src/Controllers/DownloadController.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Controllers/DownloadController.php b/src/Controllers/DownloadController.php index 5f5ce636..590d11f3 100644 --- a/src/Controllers/DownloadController.php +++ b/src/Controllers/DownloadController.php @@ -20,11 +20,9 @@ public function getDownload() if (key_exists('driver', $config) && $config['driver'] == 's3') { $duration = $this->helper->config('temporary_url_duration'); - return response()->streamDownload( - function () { + return response()->streamDownload(function () { echo file_get_contents($disk->temporaryUrl($file->path('storage'), now()->addMinutes($duration))); - }, $file_name - ); + }, $file_name); } else { return response()->download($file->path('absolute')); } From d86484f96cb225d598b4355053cb8ec17093e673 Mon Sep 17 00:00:00 2001 From: Mohamed Date: Tue, 8 Oct 2024 17:19:25 +0100 Subject: [PATCH 6/6] Update DownloadController.php --- src/Controllers/DownloadController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controllers/DownloadController.php b/src/Controllers/DownloadController.php index 590d11f3..faba9f6c 100644 --- a/src/Controllers/DownloadController.php +++ b/src/Controllers/DownloadController.php @@ -21,8 +21,8 @@ public function getDownload() if (key_exists('driver', $config) && $config['driver'] == 's3') { $duration = $this->helper->config('temporary_url_duration'); return response()->streamDownload(function () { - echo file_get_contents($disk->temporaryUrl($file->path('storage'), now()->addMinutes($duration))); - }, $file_name); + echo file_get_contents($disk->temporaryUrl($file->path('storage'), now()->addMinutes($duration))); + }, $file_name); } else { return response()->download($file->path('absolute')); }