mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +00:00
- s3 direct download
This commit is contained in:
2
public/chunks/platform.js
vendored
2
public/chunks/platform.js
vendored
File diff suppressed because one or more lines are too long
2
public/js/main.js
vendored
2
public/js/main.js
vendored
File diff suppressed because one or more lines are too long
@@ -62,7 +62,7 @@
|
||||
"/chunks/settings-password.js": "/chunks/settings-password.js?id=149343604362b7df",
|
||||
"/chunks/settings-storage.js": "/chunks/settings-storage.js?id=68765cac4e648e90",
|
||||
"/chunks/billing.js": "/chunks/billing.js?id=4f0ea0f3b2553535",
|
||||
"/chunks/platform.js": "/chunks/platform.js?id=1012744ef5111b58",
|
||||
"/chunks/platform.js": "/chunks/platform.js?id=90cb99dd8c57c5a0",
|
||||
"/chunks/files.js": "/chunks/files.js?id=5d6eb9b9f9ecd296",
|
||||
"/chunks/recent-uploads.js": "/chunks/recent-uploads.js?id=827d3a5dcce159b5",
|
||||
"/chunks/my-shared-items.js": "/chunks/my-shared-items.js?id=2a4e4e0db02cbcbb",
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
|
||||
<!--Update sharing-->
|
||||
<div v-if="pickedItem && !activeSection">
|
||||
<PopupContent>
|
||||
<PopupContent class="!overflow-initial">
|
||||
<!--Item Thumbnail-->
|
||||
<ThumbnailItem class="mb-5" :item="pickedItem" />
|
||||
|
||||
|
||||
@@ -3,29 +3,28 @@
|
||||
namespace Domain\Sharing\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Domain\Files\Actions\DownloadFileAction;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Sharing\Actions\ProtectShareRecordAction;
|
||||
use Domain\Sharing\Actions\VerifyAccessToItemWithinAction;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Domain\Traffic\Actions\RecordDownloadAction;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class DirectlyDownloadFileController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private DownloadFileAction $downloadFile,
|
||||
private RecordDownloadAction $recordDownload,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private RecordDownloadAction $recordDownload,
|
||||
private ProtectShareRecordAction $protectShareRecord,
|
||||
private VerifyAccessToItemWithinAction $verifyAccessToItemWithin,
|
||||
) {
|
||||
}
|
||||
){}
|
||||
|
||||
public function __invoke(
|
||||
Share $share
|
||||
): BinaryFileResponse|Response {
|
||||
|
||||
): Response|StreamedResponse|RedirectResponse
|
||||
{
|
||||
// Check if item is not a folder
|
||||
if ($share->type !== 'file') {
|
||||
return response('This content is not downloadable');
|
||||
@@ -35,7 +34,7 @@ class DirectlyDownloadFileController extends Controller
|
||||
($this->protectShareRecord)($share);
|
||||
|
||||
// Check if user can download file
|
||||
if (! $share->user->canDownload()) {
|
||||
if (!$share->user->canDownload()) {
|
||||
return response([
|
||||
'type' => 'error',
|
||||
'message' => 'This user action is not allowed.',
|
||||
@@ -52,11 +51,32 @@ class DirectlyDownloadFileController extends Controller
|
||||
|
||||
// Store user download size
|
||||
($this->recordDownload)(
|
||||
file_size: (int) $file->getRawOriginal('filesize'),
|
||||
file_size: (int)$file->getRawOriginal('filesize'),
|
||||
user_id: $share->user_id,
|
||||
);
|
||||
|
||||
// Finally, download file
|
||||
return ($this->downloadFile)($file, $share->user_id);
|
||||
// Get file path
|
||||
$path = "files/$share->user_id/$file->basename";
|
||||
|
||||
// Check if file exist
|
||||
if (!Storage::exists($path)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// Get pretty name
|
||||
$pretty_name = get_pretty_name($file->basename, $file->name, $file->mimetype);
|
||||
|
||||
// If s3 redirect to temporary url
|
||||
if (is_storage_driver('s3')) {
|
||||
return redirect()->away(Storage::temporaryUrl($path, now()->addHour(), [
|
||||
'ResponseAcceptRanges' => 'bytes',
|
||||
'ResponseContentType' => Storage::mimeType($path),
|
||||
'ResponseContentLength' => Storage::size($path),
|
||||
'ResponseContentRange' => 'bytes 0-600/' . Storage::size($path),
|
||||
'ResponseContentDisposition' => "attachment; filename=$pretty_name",
|
||||
]));
|
||||
}
|
||||
|
||||
return Storage::download($path, $pretty_name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user