Skip to content

Commit b2ac536

Browse files
committed
add s3 support
1 parent c31fe60 commit b2ac536

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

public/js/script.js

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

452452
if (item.thumb_url) {
453-
var image = $('<div>').css('background-image', 'url("' + item.thumb_url + '?timestamp=' + item.time + '")');
453+
var image = $('<div>').css('background-image', 'url("' + item.thumb_url + '")');
454454
} else {
455455
var icon = $('<div>').addClass('ico');
456456
var image = $('<div>').addClass('mime-icon ico-' + item.icon).append(icon);
@@ -591,7 +591,7 @@ function preview(items) {
591591
.addClass(index === 0 ? 'active' : '');
592592

593593
if (item.thumb_url) {
594-
carouselItem.find('.carousel-image').css('background-image', 'url(\'' + item.url + '?timestamp=' + item.time + '\')');
594+
carouselItem.find('.carousel-image').css('background-image', 'url(\'' + item.url + '\')');
595595
} else {
596596
carouselItem.find('.carousel-image').css('width', '50vh').append($('<div>').addClass('mime-icon ico-' + item.icon));
597597
}

src/Controllers/DownloadController.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,25 @@ 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 response()->download($file->path('absolute'));
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(
24+
function () {
25+
echo file_get_contents($disk->temporaryUrl($file->path('storage'), now()->addMinutes($duration)));
26+
}, $file_name,
27+
);
28+
} else {
29+
return response()->download($file->path('absolute'));
30+
}
1831
}
1932
}

src/LfmStorageRepository.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ 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+
50+
$duration = $this->helper->config('s3.temporary_url_expiration');
51+
return $this->disk->temporaryUrl($path, now()->addMinutes($duration));
52+
53+
else {
54+
return $this->disk->url($path);
55+
}
4756
}
4857

4958
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)