2024-05-23 16:54:06 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Http\Requests\StoreImageRequest;
|
|
|
|
|
use App\Http\Requests\UpdateImageRequest;
|
|
|
|
|
use App\Models\Image;
|
2024-06-12 19:51:41 +02:00
|
|
|
use Illuminate\Http\Response;
|
2024-05-23 16:54:06 +02:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
|
|
|
|
|
|
class ImageController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*/
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*/
|
|
|
|
|
public function store(StoreImageRequest $request)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display the specified resource.
|
|
|
|
|
*/
|
2024-06-12 19:51:41 +02:00
|
|
|
public function show(Image $image, string $size = 'original') : BinaryFileResponse|Response
|
2024-05-23 16:54:06 +02:00
|
|
|
{
|
2024-06-12 19:51:41 +02:00
|
|
|
$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);
|
2024-06-07 16:26:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display the thumbnail of the specified resource.
|
|
|
|
|
*/
|
2024-06-12 19:51:41 +02:00
|
|
|
public function thumbnail(Image $image) : BinaryFileResponse|Response
|
2024-06-07 16:26:15 +02:00
|
|
|
{
|
|
|
|
|
return $this->show($image, 'thumbnail');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display the lightbox of the specified resource.
|
|
|
|
|
*/
|
2024-06-12 19:51:41 +02:00
|
|
|
public function lightbox(Image $image) : BinaryFileResponse|Response
|
2024-06-07 16:26:15 +02:00
|
|
|
{
|
|
|
|
|
return $this->show($image, 'lightbox');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display the lightbox of the specified resource.
|
|
|
|
|
*/
|
|
|
|
|
public function download(Image $image)
|
|
|
|
|
{
|
|
|
|
|
return Storage::disk('images')->download($image->album_id . '/original/' . $image->id . '.avif', name: $image->album->name . '_' . $image->id . '.avif');
|
2024-05-23 16:54:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*/
|
|
|
|
|
public function edit(Image $image)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*/
|
|
|
|
|
public function update(UpdateImageRequest $request, Image $image)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*/
|
|
|
|
|
public function destroy(Image $image)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|