diff --git a/public/js/script.js b/public/js/script.js index fd527de4..6e422c61 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -454,7 +454,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); @@ -595,7 +595,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 29ea25e5..faba9f6c 100644 --- a/src/Controllers/DownloadController.php +++ b/src/Controllers/DownloadController.php @@ -8,12 +8,23 @@ 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 Storage::disk($this->helper->config('disk'))->download($file->path('storage')); + $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 d200b63a..9753892d 100644 --- a/src/LfmStorageRepository.php +++ b/src/LfmStorageRepository.php @@ -43,7 +43,14 @@ 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('temporary_url_duration'); + 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 70e7fd3f..20fe880f 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 121e922f..10751fa1 100644 --- a/src/views/resize.blade.php +++ b/src/views/resize.blade.php @@ -19,9 +19,9 @@
- +
-
+