Add images to tasks
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]>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Jobs\Application\Contracts\TaskImageFiles;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskImage;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\StoredTaskImage;
|
||||
|
||||
class FakeTaskImageFiles implements TaskImageFiles
|
||||
{
|
||||
/** @var array<string, true> */
|
||||
public array $files = [];
|
||||
|
||||
private int $counter = 0;
|
||||
|
||||
public function store(string $uploadedFilePath, int $taskId): StoredTaskImage
|
||||
{
|
||||
if (str_ends_with($uploadedFilePath, '.txt')) {
|
||||
throw new InvalidTaskImage;
|
||||
}
|
||||
|
||||
$this->counter++;
|
||||
$stored = new StoredTaskImage("task-images/{$taskId}/{$this->counter}.jpg", "task-images/{$taskId}/{$this->counter}-thumb.jpg", 2560, 1920);
|
||||
|
||||
foreach ($stored->paths() as $path) {
|
||||
$this->files[$path] = true;
|
||||
}
|
||||
|
||||
return $stored;
|
||||
}
|
||||
|
||||
public function delete(array $paths): void
|
||||
{
|
||||
foreach ($paths as $path) {
|
||||
unset($this->files[$path]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskImageRepository;
|
||||
use App\Modules\Jobs\Domain\Entities\TaskImage;
|
||||
|
||||
class InMemoryTaskImageRepository implements TaskImageRepository
|
||||
{
|
||||
/** @var array<int, TaskImage> */
|
||||
public array $images = [];
|
||||
|
||||
public bool $failOnSave = false;
|
||||
|
||||
private int $nextId = 1;
|
||||
|
||||
public function findForTask(int $taskId, int $imageId): ?TaskImage
|
||||
{
|
||||
$image = $this->images[$imageId] ?? null;
|
||||
|
||||
return $image !== null && $image->taskId() === $taskId ? clone $image : null;
|
||||
}
|
||||
|
||||
public function filePathsOfTask(int $taskId): array
|
||||
{
|
||||
$paths = [];
|
||||
|
||||
foreach ($this->images as $image) {
|
||||
if ($image->taskId() === $taskId) {
|
||||
array_push($paths, ...$image->file()->paths());
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
|
||||
public function save(TaskImage $image): TaskImage
|
||||
{
|
||||
if ($this->failOnSave) {
|
||||
throw new \RuntimeException('Saving failed.');
|
||||
}
|
||||
|
||||
$id = $image->id() ?? $this->nextId++;
|
||||
$this->images[$id] = TaskImage::reconstitute($id, $image->taskId(), $image->uploaderId(), $image->file(), $image->originalName(), $image->caption(), $image->uploadedAt());
|
||||
|
||||
return clone $this->images[$id];
|
||||
}
|
||||
|
||||
public function delete(TaskImage $image): void
|
||||
{
|
||||
unset($this->images[$image->id()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user