Add optional images to slides
CI / Deploy / PHP 8.4 (push) Successful in 1m10s
CI / Deploy / PHP 8.5 (push) Successful in 1m16s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped

Slides (except YouTube) can carry one image. Uploads are validated, rotated
by EXIF orientation, scaled to 1600 px and stored as WebP outside webroot,
which also strips camera metadata. Images have an alt text (or are marked
decorative) and a layout: top, side or full screen (content slides).

Files are removed after the commit when a slide is deleted or its image is
replaced, with the poll, and `bin/cake images_cleanup` sweeps leftovers.
Duplicated slides get their own file. Docker image gains gd with WebP.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-14 23:17:37 +01:00
1 parent 8c7818ee40
commit a395b50894
30 files changed
+1705 -11

No files matched your search

+29
View File
@@ -6,6 +6,7 @@ namespace App\Controller;
use App\Model\Entity\Poll;
use App\Model\Entity\Slide;
use App\Model\Table\PollsTable;
use App\Service\ImageService;
use App\Service\PollStateService;
use App\Service\VoteException;
use App\Service\VoteService;
@@ -49,6 +50,10 @@ class ParticipateController extends AppController
public function beforeFilter(EventInterface $event): void
{
parent::beforeFilter($event);
if ($this->request->getParam('action') === 'image') {
// Cacheable static content: no participant id, no cookie.
return;
}
$pid = (string)$this->request->getCookie(self::COOKIE, '');
if (!preg_match('/^[a-f0-9]{32}$/', $pid)) {
@@ -95,6 +100,30 @@ class ParticipateController extends AppController
$this->setPollInterval();
}
/**
* Serves the image of a slide of this poll. The file name is random and changes with every new
* image, so the answer can be cached for good; unknown or replaced images are 404.
*
* @param string $code Join code
* @param string $file Stored file name
* @return \Cake\Http\Response
*/
public function image(string $code, string $file): Response
{
$poll = $this->loadPoll($code);
$path = $this->fetchTable('Slides')->exists(['poll_id' => $poll->id, 'image' => $file])
? (new ImageService())->path($poll->id, $file)
: null;
if ($path === null) {
throw new NotFoundException(__('Bild nicht gefunden.'));
}
return $this->response
->withFile($path)
->withHeader('Content-Type', 'image/webp')
->withHeader('Cache-Control', 'private, max-age=31536000, immutable');
}
/**
* @param string $code Join code
* @return \Cake\Http\Response