Everyone who may comment on a task sends images to it, e.g. photos taken with a phone. The server stores an upright, at most 2560 px JPEG without EXIF data (no location) and a 400 px thumbnail on the private disk, served only to those who see the job. Uploaders change captions (also the alt text) and remove their own images; admin and management may remove anyone's (jobs.remove-any-task-image). Removing a task also removes its image files. Livewire's temporary upload limit is raised to PHP's 40 MB so that the page's own 12 MB limit gives a translated message. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
33 lines
1.1 KiB
PHP
33 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Jobs\Presentation\Http\Controllers;
|
|
|
|
use App\Modules\Jobs\Application\Contracts\TaskImageQueries;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* A task image or its thumbnail from the private disk, to those who see the
|
|
* job; with ?download=1 it is saved as a file under its original name.
|
|
*/
|
|
class ShowTaskImage
|
|
{
|
|
public function __invoke(Request $request, int $job, int $task, int $image, string $size, TaskImageQueries $images): Response
|
|
{
|
|
Gate::authorize('jobs.view-job', $job);
|
|
|
|
$file = $images->fileOf($job, $task, $image, $size === 'thumbnail') ?? abort(404);
|
|
$disk = Storage::disk('local');
|
|
|
|
abort_unless($disk->exists($file->path), 404);
|
|
|
|
$headers = ['Content-Type' => 'image/jpeg', 'Cache-Control' => 'private, max-age=86400'];
|
|
|
|
return $request->boolean('download')
|
|
? $disk->download($file->path, $file->downloadName, $headers)
|
|
: $disk->response($file->path, $file->downloadName, $headers);
|
|
}
|
|
}
|