Generate multiple avatar sizes for better performance loading and frugal traffic

This commit is contained in:
Čarodej
2021-11-03 16:28:14 +01:00
parent dc8ec5f20b
commit f139dbae08
30 changed files with 280 additions and 152 deletions

View File

@@ -11,18 +11,28 @@ class DownloadThumbnailAction
* Get image thumbnail for browser
*/
public function __invoke(
File $file,
string $user_id
string $filename,
File $file
): StreamedResponse {
// Get file path
$path = "/files/$user_id/{$file->getRawOriginal('thumbnail')}";
$path = "/files/$file->user_id/$filename";
// Check if file exist
if (! Storage::exists($path)) {
abort(404);
// Get original file path
$substituteFilePath = "/files/$file->user_id/$file->basename";
// Check if original file exist
if (! Storage::exists($substituteFilePath)) {
abort(404);
}
// Return image thumbnail
return Storage::download($substituteFilePath, $filename);
}
// Return image thumbnail
return Storage::download($path, $file->getRawOriginal('thumbnail'));
return Storage::download($path, $filename);
}
}