in image share link, return s3 url address of image

This commit is contained in:
Čarodej
2022-04-07 09:11:49 +02:00
parent ade6b05bd0
commit 7bd1079ce9
4 changed files with 91 additions and 91 deletions
@@ -18,12 +18,10 @@ class DownloadFileAction
$filePath = "files/$file->user_id/$file->basename";
// Get pretty name
$fileName = getPrettyName($file->basename, $file->name, $file->mimetype);
$fileName = getPrettyName($file);
// Check if file exist
if (! Storage::exists($filePath)) {
return response('The file not found.', 404);
}
abort_if(Storage::missing($filePath), 404, 'The file not found.');
// Format response header
$header = [
@@ -58,17 +58,24 @@ class SharePublicIndexController extends Controller
/**
* Get image from storage and show it
*/
private function get_single_image(File $file, string $user_id): StreamedResponse
private function get_single_image(File $file, string $userId): StreamedResponse|RedirectResponse
{
// Store user download size
($this->recordDownload)($file->getRawOriginal('filesize'), $user_id);
// Record user download
($this->recordDownload)($file->filesize, $userId);
// Get file path
$path = "/files/$user_id/$file->basename";
$path = "/files/$userId/$file->basename";
// Check if file exist
if (! Storage::exists($path)) {
abort(404);
abort_if(Storage::missing($path), 404);
// If s3 redirect to temporary download url
if (isStorageDriver('s3')) {
return redirect()->away(Storage::temporaryUrl($path, now()->addHour(), [
'ResponseAcceptRanges' => 'bytes',
'ResponseContentType' => Storage::mimeType($path),
'ResponseContentLength' => Storage::size($path),
]));
}
return Storage::response($path, "{$file->name}.{$file->mimetype}", [