WIP
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Http\Requests\StoreImageRequest;
|
||||
use App\Http\Requests\UpdateImageRequest;
|
||||
use App\Models\Image;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
@@ -37,15 +38,41 @@ class ImageController extends Controller
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Image $image, string $size = 'original') : BinaryFileResponse
|
||||
public function show(Image $image, string $size = 'original') : BinaryFileResponse|Response
|
||||
{
|
||||
return response()->file(Storage::disk('images')->path($image->album->id . '/' . $size . '/' . $image->id . '.avif'));
|
||||
$server = request()->server;
|
||||
$headerEtag = md5($image->updated_at->format('U') . $image->id . '_' . $size);
|
||||
$headerExpires = $image->updated_at->addYear()->toRfc2822String();
|
||||
$headerLastModified = $image->updated_at->toRfc2822String();
|
||||
|
||||
$requestModifiedSince =
|
||||
$server->has('HTTP_IF_MODIFIED_SINCE') &&
|
||||
$server->get('HTTP_IF_MODIFIED_SINCE') === $headerLastModified;
|
||||
|
||||
$requestNoneMatch =
|
||||
$server->has('HTTP_IF_NONE_MATCH') &&
|
||||
$server->get('HTTP_IF_NONE_MATCH') === $headerEtag;
|
||||
|
||||
$headers = [
|
||||
'Cache-Control' => 'max-age=0, must-revalidate, private',
|
||||
'Content-Disposition' => sprintf('inline; filename="%s"', $image->id . '_' . $size),
|
||||
'Etag' => $headerEtag,
|
||||
'Expires' => $headerExpires,
|
||||
'Last-Modified' => $headerLastModified,
|
||||
'Pragma' => 'no-cache',
|
||||
];
|
||||
|
||||
if ($requestModifiedSince || $requestNoneMatch) {
|
||||
return response('', 304)->withHeaders($headers);
|
||||
}
|
||||
|
||||
return response()->file(Storage::disk('images')->path($image->album->id . '/' . $size . '/' . $image->id . '.avif'), $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the thumbnail of the specified resource.
|
||||
*/
|
||||
public function thumbnail(Image $image) : BinaryFileResponse
|
||||
public function thumbnail(Image $image) : BinaryFileResponse|Response
|
||||
{
|
||||
return $this->show($image, 'thumbnail');
|
||||
}
|
||||
@@ -53,7 +80,7 @@ class ImageController extends Controller
|
||||
/**
|
||||
* Display the lightbox of the specified resource.
|
||||
*/
|
||||
public function lightbox(Image $image) : BinaryFileResponse
|
||||
public function lightbox(Image $image) : BinaryFileResponse|Response
|
||||
{
|
||||
return $this->show($image, 'lightbox');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user