Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add s3 support #1197

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions public/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ function loadItems(page) {
});

if (item.thumb_url) {
var image = $('<div>').css('background-image', 'url("' + item.thumb_url + '?timestamp=' + item.time + '")');
var image = $('<div>').css('background-image', 'url("' + item.thumb_url + '")');
} else {
var icon = $('<div>').addClass('ico');
var image = $('<div>').addClass('mime-icon ico-' + item.icon).append(icon);
Expand Down Expand Up @@ -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($('<div>').addClass('mime-icon ico-' + item.icon));
}
Expand Down
15 changes: 13 additions & 2 deletions src/Controllers/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
}
9 changes: 8 additions & 1 deletion src/LfmStorageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/config/lfm.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@

'disk' => 'public',

'temporary_url_duration' => 30,

'rename_file' => false,

'rename_duplicates' => false,
Expand Down
2 changes: 1 addition & 1 deletion src/views/crop.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="row no-gutters">
<div class="col-xl-8">
<div class="crop-container">
<img src="{{ $img->url . '?timestamp=' . $img->time }}" class="img img-responsive">
<img src="{{ $img->url }}" class="img img-responsive">
</div>
</div>
<div class="col-xl-4">
Expand Down
4 changes: 2 additions & 2 deletions src/views/resize.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<div class="row">
<div class="col-md-8 bg-light" id="work_space">
<div id="containment" class="d-none d-md-inline">
<img id="resize" src="{{ $img->url . '?timestamp=' . $img->time }}" height="{{ $height }}" width="{{ $width }}">
<img id="resize" src="{{ $img->url }}" height="{{ $height }}" width="{{ $width }}">
</div>
<div id="resize_mobile" style="background-image: url({{ $img->url . '?timestamp=' . $img->time }})" class="d-block d-md-none"></div>
<div id="resize_mobile" style="background-image: url({{ $img->url }})" class="d-block d-md-none"></div>
</div>
<div class="col-md-4 pt-3">
<table class="table table-compact table-striped">
Expand Down