28 lines
838 B
PHP
28 lines
838 B
PHP
<?php
|
|
|
|
namespace App\Modules\Inventory\Presentation\Http\Controllers;
|
|
|
|
use App\Modules\Inventory\Application\Contracts\StockQueries;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* A stock item's image or its thumbnail from the private disk, to those who
|
|
* see the stock.
|
|
*/
|
|
class ShowStockItemImage
|
|
{
|
|
public function __invoke(int $item, string $size, StockQueries $stock): Response
|
|
{
|
|
Gate::authorize('inventory.view');
|
|
|
|
$path = $stock->imagePathOf($item, $size === 'thumbnail') ?? abort(404);
|
|
$disk = Storage::disk('local');
|
|
|
|
abort_unless($disk->exists($path), 404);
|
|
|
|
return $disk->response($path, basename($path), ['Content-Type' => 'image/jpeg', 'Cache-Control' => 'private, max-age=86400']);
|
|
}
|
|
}
|