Skip to content

Commit 45018d1

Browse files
authored
Merge pull request #1197 from slimani-dev/s3_support
add s3 support
2 parents ba8a3a7 + d86484f commit 45018d1

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

public/js/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ function loadItems(page) {
455455
});
456456

457457
if (item.thumb_url) {
458-
var image = $('<div>').css('background-image', 'url("' + item.thumb_url + '?timestamp=' + item.time + '")');
458+
var image = $('<div>').css('background-image', 'url("' + item.thumb_url + '")');
459459
} else {
460460
var icon = $('<div>').addClass('ico');
461461
var image = $('<div>').addClass('mime-icon ico-' + item.icon).append(icon);
@@ -601,7 +601,7 @@ function preview(items) {
601601
.addClass(index === 0 ? 'active' : '');
602602

603603
if (item.thumb_url) {
604-
carouselItem.find('.carousel-image').css('background-image', 'url(\'' + item.url + '?timestamp=' + item.time + '\')');
604+
carouselItem.find('.carousel-image').css('background-image', 'url(\'' + item.url + '\')');
605605
} else {
606606
carouselItem.find('.carousel-image').css('width', '50vh').append($('<div>').addClass('mime-icon ico-' + item.icon));
607607
}

src/Controllers/DownloadController.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@ class DownloadController extends LfmController
88
{
99
public function getDownload()
1010
{
11-
$file = $this->lfm->setName(request('file'));
11+
$file_name = request('file');
12+
$file = $this->lfm->setName($file_name);
1213

1314
if (!Storage::disk($this->helper->config('disk'))->exists($file->path('storage'))) {
1415
abort(404);
1516
}
1617

17-
return Storage::disk($this->helper->config('disk'))->download($file->path('storage'));
18+
$disk = Storage::disk($this->helper->config('disk'));
19+
$config = $disk->getConfig();
20+
21+
if (key_exists('driver', $config) && $config['driver'] == 's3') {
22+
$duration = $this->helper->config('temporary_url_duration');
23+
return response()->streamDownload(function () {
24+
echo file_get_contents($disk->temporaryUrl($file->path('storage'), now()->addMinutes($duration)));
25+
}, $file_name);
26+
} else {
27+
return response()->download($file->path('absolute'));
28+
}
1829
}
1930
}

src/LfmStorageRepository.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ public function save($file)
4343

4444
public function url($path)
4545
{
46-
return $this->disk->url($path);
46+
$config = $this->disk->getConfig();
47+
48+
if (key_exists('driver', $config) && $config['driver'] == 's3') {
49+
$duration = $this->helper->config('temporary_url_duration');
50+
return $this->disk->temporaryUrl($path, now()->addMinutes($duration));
51+
} else {
52+
return $this->disk->url($path);
53+
}
4754
}
4855

4956
public function makeDirectory()

src/config/lfm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@
9696

9797
'disk' => 'public',
9898

99+
'temporary_url_duration' => 30,
100+
99101
'rename_file' => false,
100102

101103
'rename_duplicates' => false,

src/views/crop.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="row no-gutters">
22
<div class="col-xl-8">
33
<div class="crop-container">
4-
<img src="{{ $img->url . '?timestamp=' . $img->time }}" class="img img-responsive">
4+
<img src="{{ $img->url }}" class="img img-responsive">
55
</div>
66
</div>
77
<div class="col-xl-4">

src/views/resize.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
<div class="row">
2020
<div class="col-md-8 bg-light" id="work_space">
2121
<div id="containment" class="d-none d-md-inline">
22-
<img id="resize" src="{{ $img->url . '?timestamp=' . $img->time }}" height="{{ $height }}" width="{{ $width }}">
22+
<img id="resize" src="{{ $img->url }}" height="{{ $height }}" width="{{ $width }}">
2323
</div>
24-
<div id="resize_mobile" style="background-image: url({{ $img->url . '?timestamp=' . $img->time }})" class="d-block d-md-none"></div>
24+
<div id="resize_mobile" style="background-image: url({{ $img->url }})" class="d-block d-md-none"></div>
2525
</div>
2626
<div class="col-md-4 pt-3">
2727
<table class="table table-compact table-striped">

0 commit comments

Comments
 (0)