From 63b42b366c44e009d92b5c3a3947902b47714000 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 28 Nov 2026 09:37:00 +0100 Subject: [PATCH] Lege Bildfassungen an und liefere sie zwischengespeichert aus (ADR-63) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vorschaubilder entstehen zusätzlich als klein (360 px) und mittel (960 px), Website-Bilder in den Breiten 640, 1280 und 1920. Auswahl, Listen und Karten laden die kleinen Fassungen; die Website nutzt srcset. Adressen tragen Größe und Version und werden dauerhaft zwischengespeichert (ETag, 304). Die Website-Route läuft ohne Sitzung und Cookies. Bestand füllt sich über die Warteschlange oder mit media:varianten. Die Optionsliste des CMS fragt nicht mehr je Eintrag ab. Co-Authored-By: Claude Sonnet 5.5 --- app/Console/Commands/DeriveMediaVariants.php | 71 ++++ app/Domain/Catalog/PresentationMedia.php | 4 +- app/Domain/Catalog/TemplateImage.php | 2 +- .../Cms/Catalog/PublicCatalogReader.php | 2 +- .../Cms/Catalog/PublicMaterialReader.php | 2 +- app/Domain/Cms/Sections/SectionRenderer.php | 2 +- .../Cms/Widgets/Support/WebsiteImage.php | 35 +- app/Domain/Cms/Widgets/Types/CardsWidget.php | 1 + app/Domain/Cms/Widgets/Types/HeroWidget.php | 1 + .../Cms/Widgets/Types/ImageTextWidget.php | 1 + .../Cms/Widgets/Types/MediaCardWidget.php | 2 +- .../Cms/Widgets/Types/PremiumCardWidget.php | 1 + .../Cms/Widgets/Types/ProgramCardWidget.php | 2 +- app/Domain/Media/ImageVariants.php | 174 +++++++++ app/Domain/Media/PresentationFile.php | 2 + app/Domain/Media/ThumbnailDeriver.php | 6 + app/Domain/Media/ThumbnailRef.php | 27 +- app/Domain/Media/WebsiteMedia.php | 29 +- app/Domain/Media/WebsitePresentation.php | 14 + .../Pages/EditContentElement.php | 2 +- .../Pages/ViewContentElement.php | 4 +- .../Pages/ListLicenseArticles.php | 2 +- app/Filament/Support/EditorialCatalog.php | 26 +- app/Filament/Support/MediaLibrary.php | 2 +- .../Controllers/Concerns/ServesImages.php | 62 ++++ .../EditorialPreviewController.php | 15 +- .../Controllers/Member/LibraryController.php | 14 +- .../Controllers/WebsiteMediaController.php | 51 ++- app/Http/LibraryCatalog.php | 5 +- app/Http/MemberLicenses.php | 4 +- app/Jobs/DeriveImageVariants.php | 28 ++ app/Jobs/DeriveWebsiteVariants.php | 38 ++ app/Jobs/PublishWebsiteMedia.php | 9 + .../12_Entscheidungsprotokoll_ADR.md | 17 + docs/architektur/bildvarianten.md | 42 +++ .../views/components/vw/eintrag.blade.php | 2 +- resources/views/content/player.blade.php | 2 +- .../filament/verwaltung/aufbau.blade.php | 4 +- .../verwaltung/praesentation.blade.php | 2 +- resources/views/member/article.blade.php | 2 +- resources/views/member/program.blade.php | 2 +- resources/views/widgets/cards.blade.php | 2 +- resources/views/widgets/hero.blade.php | 2 +- resources/views/widgets/image_text.blade.php | 2 +- .../views/widgets/premium_card.blade.php | 2 +- routes/web.php | 20 +- tests/Feature/BildvariantenTest.php | 338 ++++++++++++++++++ tests/Feature/CmsCardTrailerTest.php | 2 +- tests/Feature/CmsImageTextMediaTest.php | 4 +- tests/Feature/CmsPremiumCardsTest.php | 4 +- tests/Feature/CmsWebsiteMediaTest.php | 12 +- tests/Feature/FilmStillTest.php | 3 +- tests/Feature/LibraryProgramTest.php | 2 +- tests/Feature/ShopTilesTest.php | 9 +- 54 files changed, 1033 insertions(+), 82 deletions(-) create mode 100644 app/Console/Commands/DeriveMediaVariants.php create mode 100644 app/Domain/Media/ImageVariants.php create mode 100644 app/Http/Controllers/Concerns/ServesImages.php create mode 100644 app/Jobs/DeriveImageVariants.php create mode 100644 app/Jobs/DeriveWebsiteVariants.php create mode 100644 docs/architektur/bildvarianten.md create mode 100644 tests/Feature/BildvariantenTest.php diff --git a/app/Console/Commands/DeriveMediaVariants.php b/app/Console/Commands/DeriveMediaVariants.php new file mode 100644 index 0000000..5ed626e --- /dev/null +++ b/app/Console/Commands/DeriveMediaVariants.php @@ -0,0 +1,71 @@ +where('thumbnail_path', 'like', 'vorschau/%') + ->pluck('thumbnail_path') + ->each(function (mixed $path) use (&$paths): void { + if (is_string($path)) { + $paths[$path] = true; + } + }); + } + + $missing = array_values(array_filter( + array_keys($paths), + fn (string $path): bool => ! str_contains($path, '..') + && ! $derived->exists(ImageVariants::path($path, 'klein')) + && $derived->exists($path), + )); + + $websiteIds = ContentElement::query() + ->where('output_class', 'bild') + ->whereNotNull('website_released_at') + ->whereNotNull('website_public_path') + ->pluck('id') + ->all(); + + $this->info(count($missing).' Vorschaubilder ohne Fassungen, '.count($websiteIds).' freigegebene Website-Bilder.'); + + if ($this->option('pretend')) { + return self::SUCCESS; + } + + foreach ($missing as $path) { + $this->option('now') ? DeriveImageVariants::dispatchSync($path) : DeriveImageVariants::dispatch($path); + } + + foreach ($websiteIds as $id) { + $this->option('now') ? DeriveWebsiteVariants::dispatchSync((int) $id) : DeriveWebsiteVariants::dispatch((int) $id); + } + + $this->info($this->option('now') ? 'Fassungen angelegt.' : 'In die Warteschlange gelegt.'); + + return self::SUCCESS; + } +} diff --git a/app/Domain/Catalog/PresentationMedia.php b/app/Domain/Catalog/PresentationMedia.php index 26bc909..50add58 100644 --- a/app/Domain/Catalog/PresentationMedia.php +++ b/app/Domain/Catalog/PresentationMedia.php @@ -49,7 +49,7 @@ public function rows(Model $subject): array ? (string) ($element->display_title ?: $element->working_title) : 'Medium fehlt', 'image' => $element instanceof ContentElement - ? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path) + ? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at) : null, 'kind' => $element?->editorialContentKind?->label, 'output' => $element instanceof ContentElement ? (string) $element->output_class : '', @@ -134,7 +134,7 @@ public function describe(array $staged): array ? (string) ($element->display_title ?: $element->working_title) : 'Medium fehlt', 'image' => $element instanceof ContentElement - ? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path) + ? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at) : null, 'kind' => $element?->editorialContentKind?->label, 'output' => $element instanceof ContentElement ? (string) $element->output_class : '', diff --git a/app/Domain/Catalog/TemplateImage.php b/app/Domain/Catalog/TemplateImage.php index 348c5ac..3a49faa 100644 --- a/app/Domain/Catalog/TemplateImage.php +++ b/app/Domain/Catalog/TemplateImage.php @@ -104,7 +104,7 @@ public static function previewUrl(?string $target): ?string return route('website.media', $element); } - return app(EditorialCatalog::class)->cardUrl('element', $element->id, $element->thumbnail_path); + return app(EditorialCatalog::class)->cardUrl('element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at); } /** diff --git a/app/Domain/Cms/Catalog/PublicCatalogReader.php b/app/Domain/Cms/Catalog/PublicCatalogReader.php index bd964f6..41a0235 100644 --- a/app/Domain/Cms/Catalog/PublicCatalogReader.php +++ b/app/Domain/Cms/Catalog/PublicCatalogReader.php @@ -319,7 +319,7 @@ public function subject(mixed $id, bool $includeNonPublic): ?CardSubject notice: $notice, visual: 'catalog', visualLabel: $kind, - previewImage: $includeNonPublic ? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path) : null, + previewImage: $includeNonPublic ? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path, 'mittel', $composition->updated_at) : null, missing: $missing, texts: $texts, ); diff --git a/app/Domain/Cms/Catalog/PublicMaterialReader.php b/app/Domain/Cms/Catalog/PublicMaterialReader.php index 0fc5e96..1e2e6db 100644 --- a/app/Domain/Cms/Catalog/PublicMaterialReader.php +++ b/app/Domain/Cms/Catalog/PublicMaterialReader.php @@ -221,7 +221,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ? $missing[] = 'Kein Anzeigetitel gepflegt; die Karte zeigt den Arbeitstitel.'; } - $previewImage = $includeNonPublic ? ThumbnailRef::url('editorial.card', 'element', (int) $element->id, $shown->thumbnail_path) : null; + $previewImage = $includeNonPublic ? ThumbnailRef::url('editorial.card', 'element', (int) $element->id, $shown->thumbnail_path, 'mittel', $shown->updated_at) : null; return new CardSubject( title: $title, diff --git a/app/Domain/Cms/Sections/SectionRenderer.php b/app/Domain/Cms/Sections/SectionRenderer.php index 2ae5bd0..2a3f992 100644 --- a/app/Domain/Cms/Sections/SectionRenderer.php +++ b/app/Domain/Cms/Sections/SectionRenderer.php @@ -115,7 +115,7 @@ private function renderSection(array $section, array $cells, int $index, RenderC $style = SectionStyle::fromStored($section['style'] ?? []); $columns = SectionLayouts::columns(array_column($cells, 'units')); // Hintergrundbild aus dem Medienmanager: öffentlich nur mit Website-Freigabe (WebsiteImage → WebsiteMedia). - $imageUrl = $style['background'] === 'image' ? app(WebsiteImage::class)->url($style['image'], $context->preview) : null; + $imageUrl = $style['background'] === 'image' ? app(WebsiteImage::class)->url($style['image'], $context->preview, 1920) : null; $hasImage = $imageUrl !== null; $classes = [ diff --git a/app/Domain/Cms/Widgets/Support/WebsiteImage.php b/app/Domain/Cms/Widgets/Support/WebsiteImage.php index 08cbb06..b530acb 100644 --- a/app/Domain/Cms/Widgets/Support/WebsiteImage.php +++ b/app/Domain/Cms/Widgets/Support/WebsiteImage.php @@ -86,7 +86,7 @@ public function elementId(mixed $value): ?int return is_int($id) ? $id : null; } - public function presentation(mixed $value): ?WebsitePresentation + public function presentation(mixed $value, ?ContentElement $loaded = null): ?WebsitePresentation { $id = $this->elementId($value); @@ -95,7 +95,8 @@ public function presentation(mixed $value): ?WebsitePresentation } if (! array_key_exists($id, $this->presentations)) { - $this->presentations[$id] = $this->media->present($id) ?? false; + // Ein schon geladenes Medium wird weitergereicht (kein zweiter Zugriff je Eintrag in der Auswahl). + $this->presentations[$id] = $this->media->present($loaded?->getKey() === $id ? $loaded : $id) ?? false; } return $this->presentations[$id] ?: null; @@ -105,12 +106,12 @@ public function presentation(mixed $value): ?WebsitePresentation * Bildadresse für die Darstellung. Öffentlich nur freigegebene Medien (oder frühere CMS-Bilder ohne Zuordnung); * in der Redaktionsvorschau zusätzlich das Vorschaubild eines nicht freigegebenen Mediums. */ - public function url(mixed $value, bool $preview = false): ?string + public function url(mixed $value, bool $preview = false, ?int $width = null): ?string { $presentation = $this->presentation($value); if ($presentation !== null) { - return $presentation->kind === 'bild' ? $presentation->url : null; + return $presentation->kind === 'bild' ? $presentation->urlForWidth($width) : null; } $id = $this->elementId($value); @@ -122,7 +123,7 @@ public function url(mixed $value, bool $preview = false): ?string $element = ContentElement::query()->find($id); - return $element === null ? null : ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path); + return $element === null ? null : ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at); } $legacy = self::normalize($value); @@ -134,6 +135,14 @@ public function url(mixed $value, bool $preview = false): ?string return is_string($legacy) ? PublicMedia::url($legacy) : null; } + /** `srcset` des freigegebenen Bildes (mehrere Breiten), sonst null. Für Hero, Bild mit Text, Karten. */ + public function srcset(mixed $value): ?string + { + $presentation = $this->presentation($value); + + return $presentation !== null && $presentation->kind === 'bild' ? $presentation->srcset : null; + } + /** Alternativtext: Angabe im Widget, sonst der Alternativtext des Mediums. */ public function alt(mixed $value, mixed $override = null): string { @@ -169,7 +178,7 @@ public function previewNotice(mixed $value, string $label = 'Das gewählte Bild' * * @return array{public: bool, state: string, title: string, note: string, thumb: ?string, manageUrl: ?string}|null */ - public function status(mixed $value): ?array + public function status(mixed $value, ?ContentElement $loaded = null): ?array { $value = self::normalize($value); @@ -194,16 +203,16 @@ public function status(mixed $value): ?array ]; } - $element = ContentElement::query()->with('editorialContentKind')->find($id); + $element = $loaded?->getKey() === $id ? $loaded : ContentElement::query()->with('editorialContentKind')->find($id); if ($element === null) { return ['public' => false, 'state' => 'missing', 'title' => 'Medium '.$id, 'note' => 'Das Medium gibt es nicht mehr.', 'thumb' => null, 'manageUrl' => null]; } $title = (string) ($element->display_title ?: $element->working_title); - $thumb = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path); + $thumb = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at); $manageUrl = ContentElementResource::getUrl('view', ['record' => $element]); - $public = $this->presentation($id) !== null; + $public = $this->presentation($id, $element) !== null; $note = match (true) { $public => 'Für die Website freigegeben.', @@ -292,7 +301,7 @@ public function options(?string $search = null, int $limit = 60): array $options = []; foreach ($elements as $element) { if (self::isSelectable($element)) { - $options[$element->id] = $this->optionHtml($element->id); + $options[$element->id] = $this->optionHtml($element->id, $element); } } @@ -300,9 +309,9 @@ public function options(?string $search = null, int $limit = 60): array } /** HTML-Bezeichnung einer Option oder des gewählten Werts (auch für frühere Pfade). */ - public function optionHtml(mixed $value): ?string + public function optionHtml(mixed $value, ?ContentElement $loaded = null): ?string { - $status = $this->status($value); + $status = $this->status($value, $loaded); if ($status === null) { return null; @@ -315,7 +324,7 @@ public function optionHtml(mixed $value): ?string default => ['warn', 'Website: nicht freigegeben'], }; $thumb = $status['thumb'] !== null - ? '' + ? '' : ''; return ''.$thumb diff --git a/app/Domain/Cms/Widgets/Types/CardsWidget.php b/app/Domain/Cms/Widgets/Types/CardsWidget.php index aac1621..4f40c95 100644 --- a/app/Domain/Cms/Widgets/Types/CardsWidget.php +++ b/app/Domain/Cms/Widgets/Types/CardsWidget.php @@ -302,6 +302,7 @@ public function resolve(array $widget, RenderContext $context): array 'linkLabel' => filled($item['link_label'] ?? null) ? $item['link_label'] : self::DEFAULT_LINK_LABEL, 'symbol' => HeadingAccent::symbol(['symbol' => $item['symbol'] ?? null]), 'imageUrl' => $images->url($item['image'] ?? null, $context->preview), + 'imageSrcset' => $images->srcset($item['image'] ?? null), ]; if ($context->preview && ($notice = $images->previewNotice($item['image'] ?? null, 'Das Bild der Karte „'.$item['title'].'“')) !== null) { diff --git a/app/Domain/Cms/Widgets/Types/HeroWidget.php b/app/Domain/Cms/Widgets/Types/HeroWidget.php index 3e5f097..aeea416 100644 --- a/app/Domain/Cms/Widgets/Types/HeroWidget.php +++ b/app/Domain/Cms/Widgets/Types/HeroWidget.php @@ -250,6 +250,7 @@ public function resolve(array $widget, RenderContext $context): array return [ 'video' => $video, 'imageUrl' => $images->url($image, $context->preview), + 'imageSrcset' => $images->srcset($image), 'imageAlt' => $images->alt($image, $widget['data']['alt'] ?? null), 'imageNotice' => $context->preview ? $images->previewNotice($image) : null, 'actions' => $actions, diff --git a/app/Domain/Cms/Widgets/Types/ImageTextWidget.php b/app/Domain/Cms/Widgets/Types/ImageTextWidget.php index 0f69fa1..7d04374 100644 --- a/app/Domain/Cms/Widgets/Types/ImageTextWidget.php +++ b/app/Domain/Cms/Widgets/Types/ImageTextWidget.php @@ -329,6 +329,7 @@ public function resolve(array $widget, RenderContext $context): array return [ 'imageUrl' => $imageUrl, + 'imageSrcset' => $imageUrl === null ? null : $images->srcset($image), 'imageAlt' => $imageAlt, 'imageNotice' => $context->preview ? $images->previewNotice($image) : null, 'video' => $video, diff --git a/app/Domain/Cms/Widgets/Types/MediaCardWidget.php b/app/Domain/Cms/Widgets/Types/MediaCardWidget.php index 6d810d5..b101387 100644 --- a/app/Domain/Cms/Widgets/Types/MediaCardWidget.php +++ b/app/Domain/Cms/Widgets/Types/MediaCardWidget.php @@ -130,7 +130,7 @@ protected function filmFieldData(?ContentElement $film): array ? route('content.website-frame', ['element' => $film]) : null, 'filmHasThumbnail' => $film instanceof ContentElement && is_string($film->thumbnail_path) && $film->thumbnail_path !== '', - 'filmThumbnailUrl' => $film instanceof ContentElement ? ThumbnailRef::url('editorial.card', 'element', (int) $film->id, $film->thumbnail_path) : null, + 'filmThumbnailUrl' => $film instanceof ContentElement ? ThumbnailRef::url('editorial.card', 'element', (int) $film->id, $film->thumbnail_path, 'mittel', $film->updated_at) : null, 'filmStartSecond' => $film instanceof ContentElement ? ($stills->thumbnailSecond($film) ?? '0') : '0', ]; } diff --git a/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php b/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php index aeabedb..d99b86a 100644 --- a/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php +++ b/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php @@ -349,6 +349,7 @@ public function resolve(array $widget, RenderContext $context): array 'clip' => $clip, 'cardStyle' => $subject?->style ?? $this->cardStyle(), 'imageUrl' => app(WebsiteImage::class)->url($imageRef, $context->preview), + 'imageSrcset' => app(WebsiteImage::class)->srcset($imageRef), 'alt' => app(WebsiteImage::class)->alt($imageRef, $data['alt'] ?? null), 'imageNotice' => $context->preview ? app(WebsiteImage::class)->previewNotice($imageRef, 'Das Kartenbild') : null, 'focus' => PremiumFields::focus($data, 66, 45), diff --git a/app/Domain/Cms/Widgets/Types/ProgramCardWidget.php b/app/Domain/Cms/Widgets/Types/ProgramCardWidget.php index 1ae6faa..1874521 100644 --- a/app/Domain/Cms/Widgets/Types/ProgramCardWidget.php +++ b/app/Domain/Cms/Widgets/Types/ProgramCardWidget.php @@ -65,7 +65,7 @@ protected function imageSourceFields(): array 'composition' => $composition, 'compositionTitle' => $composition instanceof Composition ? (string) ($composition->display_title ?: $composition->designation) : '', 'compositionThumbnailUrl' => $composition instanceof Composition && app(CompositionStill::class)->hasThumbnail($composition) - ? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path) + ? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path, 'mittel', $composition->updated_at) : null, ]; }), diff --git a/app/Domain/Media/ImageVariants.php b/app/Domain/Media/ImageVariants.php new file mode 100644 index 0000000..b7ceaeb --- /dev/null +++ b/app/Domain/Media/ImageVariants.php @@ -0,0 +1,174 @@ + */ + public const SIZES = ['klein' => 360, 'mittel' => 960]; + + /** @var list */ + public const PUBLIC_WIDTHS = [640, 1280, 1920]; + + private const QUALITY = 80; + + public static function isSize(mixed $size): bool + { + return is_string($size) && array_key_exists($size, self::SIZES); + } + + public static function isPublicWidth(mixed $width): bool + { + return is_int($width) && in_array($width, self::PUBLIC_WIDTHS, true); + } + + /** `vorschau/element-12.jpg` → `vorschau/element-12-klein.jpg` */ + public static function path(string $base, string $size): string + { + $extension = pathinfo($base, PATHINFO_EXTENSION); + $stem = $extension === '' ? $base : substr($base, 0, -(strlen($extension) + 1)); + + return $stem.'-'.$size.'.jpg'; + } + + /** `website/12/datei.jpg` → `website/12/datei-640.jpg` */ + public static function publicPath(string $base, int $width): string + { + return self::path($base, (string) $width); + } + + /** + * Pfad, der für die Größe ausgeliefert wird: die Fassung, wenn es sie gibt, sonst die Hauptdatei. + */ + public static function resolve(Filesystem $disk, string $base, ?string $size): string + { + if (! self::isSize($size)) { + return $base; + } + + $variant = self::path($base, (string) $size); + + return $disk->exists($variant) ? $variant : $base; + } + + /** + * Legt die Fassungen der Verwaltungsoberfläche zur Hauptdatei an (Warteschlange). Ist die Quelle nicht breiter als die + * Stufe, entfällt die Fassung, und eine ältere wird entfernt. + * + * @return list Pfade der geschriebenen Fassungen + */ + public static function generate(Filesystem $disk, string $base): array + { + $targets = []; + + foreach (self::SIZES as $name => $width) { + $targets[self::path($base, $name)] = $width; + } + + return self::write($disk, $disk, $base, $targets); + } + + /** + * Legt die Breiten für die Website neben der öffentlichen Hauptdatei an. Nur JPEG-Quellen: andere Formate (PNG, GIF, + * WebP) können Transparenz tragen, die ein JPEG nicht hält; sie bleiben unverändert. + * + * @return list Pfade der geschriebenen Fassungen + */ + public static function generatePublic(Filesystem $source, Filesystem $target, string $sourcePath, string $publicBase): array + { + if (! in_array(strtolower(pathinfo($publicBase, PATHINFO_EXTENSION)), ['jpg', 'jpeg'], true)) { + return []; + } + + $targets = []; + + foreach (self::PUBLIC_WIDTHS as $width) { + $targets[self::publicPath($publicBase, $width)] = $width; + } + + return self::write($source, $target, $sourcePath, $targets); + } + + /** Entfernt alle Fassungen zu einer öffentlichen Hauptdatei (Rücknahme, Ersatz). */ + public static function deletePublic(Filesystem $disk, string $publicBase): void + { + foreach (self::PUBLIC_WIDTHS as $width) { + $disk->delete(self::publicPath($publicBase, $width)); + } + } + + /** + * @param array $targets Zielpfad → Breite + * @return list + */ + private static function write(Filesystem $source, Filesystem $target, string $sourcePath, array $targets): array + { + if (! $source->exists($sourcePath)) { + return []; + } + + $bytes = $source->get($sourcePath); + $image = is_string($bytes) && $bytes !== '' ? @imagecreatefromstring($bytes) : false; + + if ($image === false) { + return []; + } + + $width = imagesx($image); + $height = imagesy($image); + $written = []; + + foreach ($targets as $path => $targetWidth) { + if ($width <= $targetWidth) { + $target->delete($path); + + continue; + } + + $encoded = self::scaled($image, $width, $height, $targetWidth); + + if ($encoded !== null && $target->put($path, $encoded)) { + $written[] = $path; + } + } + + imagedestroy($image); + + return $written; + } + + private static function scaled(\GdImage $image, int $width, int $height, int $targetWidth): ?string + { + $targetHeight = (int) max(1, round($height * ($targetWidth / max(1, $width)))); + $canvas = imagecreatetruecolor($targetWidth, $targetHeight); + imagefill($canvas, 0, 0, (int) imagecolorallocate($canvas, 255, 255, 255)); + imagecopyresampled($canvas, $image, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height); + imageinterlace($canvas, true); + ob_start(); + imagejpeg($canvas, null, self::QUALITY); + $bytes = ob_get_clean(); + imagedestroy($canvas); + + return is_string($bytes) && $bytes !== '' ? $bytes : null; + } +} diff --git a/app/Domain/Media/PresentationFile.php b/app/Domain/Media/PresentationFile.php index 2a42fec..af27199 100644 --- a/app/Domain/Media/PresentationFile.php +++ b/app/Domain/Media/PresentationFile.php @@ -89,6 +89,7 @@ public function place(ContentElement $element, string $incoming): void } if ($element->output_class === 'bild') { + ImageVariants::generate(Storage::disk('media_derived'), $target); $element->thumbnail_path = $target; $element->thumbnail_source = 'eigen'; } else { @@ -97,6 +98,7 @@ public function place(ContentElement $element, string $incoming): void $element->thumbnail_error = null; $element->save(); + $element->touch(); Storage::disk('cms_incoming')->delete($incoming); } diff --git a/app/Domain/Media/ThumbnailDeriver.php b/app/Domain/Media/ThumbnailDeriver.php index 2e4a998..d3ae708 100644 --- a/app/Domain/Media/ThumbnailDeriver.php +++ b/app/Domain/Media/ThumbnailDeriver.php @@ -335,6 +335,7 @@ private function frame(ContentElement $element, ContentElementVersion $version, return; } + ImageVariants::generate($disk, $target); $element->thumbnail_path = $target; if (! filled($element->thumbnail_alt)) { $element->thumbnail_alt = $element->working_title; @@ -344,6 +345,7 @@ private function frame(ContentElement $element, ContentElementVersion $version, $element->thumbnail_source = 'frame:'.$version->id.'@0'; } $element->save(); + $element->touch(); } private function still(ContentElement|Composition $subject, Filesystem $disk, string $file, string $name): void @@ -388,6 +390,7 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st $path = 'vorschau/'.$name.'.jpg'; Storage::disk('media_derived')->put($path, $bytes); + ImageVariants::generate(Storage::disk('media_derived'), $path); $subject->thumbnail_path = $path; if (! filled($subject->thumbnail_alt)) { @@ -396,6 +399,9 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st $subject->thumbnail_error = null; $subject->save(); + // Die Adresse trägt die Version (updated_at) und wird dauerhaft zwischengespeichert: Ein neu abgeleitetes Bild + // unter gleichem Pfad muss die Version ändern, auch wenn sonst nichts an der Zeile anders ist. + $subject->touch(); } private function rememberElement(ContentElement $element, string $source): void diff --git a/app/Domain/Media/ThumbnailRef.php b/app/Domain/Media/ThumbnailRef.php index ba80801..d4be226 100644 --- a/app/Domain/Media/ThumbnailRef.php +++ b/app/Domain/Media/ThumbnailRef.php @@ -2,14 +2,37 @@ namespace App\Domain\Media; +use Carbon\CarbonInterface; + class ThumbnailRef { - public static function url(string $route, string $kind, int $id, mixed $path): ?string + /** + * Adresse eines Vorschaubildes. + * + * @param string|null $size `klein` (Auswahl, Listen, Karten), `mittel` (Detail, Vorschau) oder null für die volle Datei + * @param CarbonInterface|int|string|null $version Stand des Bildes (zum Beispiel `updated_at`). Mit Version darf der Browser das Bild + * dauerhaft behalten; ohne Version fragt er jedes Mal nach (ETag). + */ + public static function url(string $route, string $kind, int $id, mixed $path, ?string $size = null, CarbonInterface|int|string|null $version = null): ?string { if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) { return null; } - return route($route, ['kind' => $kind, 'subject' => $id]); + $query = []; + + if (ImageVariants::isSize($size)) { + $query['g'] = $size; + } + + if ($version instanceof CarbonInterface) { + $version = $version->getTimestamp(); + } + + if ($version !== null && $version !== '') { + $query['v'] = $version; + } + + return route($route, ['kind' => $kind, 'subject' => $id] + $query); } } diff --git a/app/Domain/Media/WebsiteMedia.php b/app/Domain/Media/WebsiteMedia.php index ba10478..b46ba73 100644 --- a/app/Domain/Media/WebsiteMedia.php +++ b/app/Domain/Media/WebsiteMedia.php @@ -45,10 +45,37 @@ public function present(ContentElement|int $element): ?WebsitePresentation 'audio' => 'audio', default => 'bild', }, - url: route('website.media', $element), + // Bilder tragen den Zeitpunkt der Freigabe in der Adresse (dauerhaft zwischenspeicherbar); Film und Hörstück bleiben unverändert. + url: $element->output_class === 'film' || $element->output_class === 'audio' + ? route('website.media', $element) + : route('website.media', ['element' => $element, 'v' => $element->website_released_at->getTimestamp()]), + srcset: $this->srcset($element, $path), ); } + /** + * `srcset` eines freigegebenen JPEG-Bildes: die Breiten aus {@see ImageVariants::PUBLIC_WIDTHS} und die volle Datei. + * Fehlt eine Breite noch (Bestand), liefert die Adresse die volle Datei und stößt das Anlegen an; die Beschreibung bleibt + * dann ungenau, das Bild aber richtig. PNG, GIF und WebP bleiben ohne Fassungen (Transparenz). + */ + private function srcset(ContentElement $element, string $path): ?string + { + if ($element->output_class !== 'bild' || ! in_array(strtolower(pathinfo($path, PATHINFO_EXTENSION)), ['jpg', 'jpeg'], true)) { + return null; + } + + $version = $element->website_released_at->getTimestamp(); + $entries = []; + + foreach (ImageVariants::PUBLIC_WIDTHS as $width) { + $entries[] = route('website.media', ['element' => $element, 'w' => $width, 'v' => $version]).' '.$width.'w'; + } + + $entries[] = route('website.media', ['element' => $element, 'v' => $version]).' 2400w'; + + return implode(', ', $entries); + } + /** * Slideshow: freigegebene Medien in der angegebenen Reihenfolge. Nicht freigegebene Einträge entfallen. * diff --git a/app/Domain/Media/WebsitePresentation.php b/app/Domain/Media/WebsitePresentation.php index d93072b..0e21bdd 100644 --- a/app/Domain/Media/WebsitePresentation.php +++ b/app/Domain/Media/WebsitePresentation.php @@ -15,5 +15,19 @@ public function __construct( public readonly ?string $credit, public readonly string $kind, public readonly string $url, + /** Bildadressen in mehreren Breiten für `srcset` (nur Bilder, deren Breiten die Warteschlange anlegt), sonst null. */ + public readonly ?string $srcset = null, ) {} + + /** + * Adresse in einer der Breiten aus {@see ImageVariants::PUBLIC_WIDTHS}; ohne Breiten (oder bei anderer Breite) die volle Datei. + */ + public function urlForWidth(?int $width): string + { + if ($width === null || $this->srcset === null || ! ImageVariants::isPublicWidth($width)) { + return $this->url; + } + + return $this->url.(str_contains($this->url, '?') ? '&' : '?').'w='.$width; + } } diff --git a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php index 5f6e298..215e1a3 100644 --- a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php @@ -119,7 +119,7 @@ public function form(Schema $schema): Schema Placeholder::make('thumbnail_current')->label('Aktuelles Vorschaubild')->content(function (): HtmlString { /** @var ContentElement $element */ $element = $this->getRecord(); - $url = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path); + $url = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at); $caption = match ($element->thumbnail_source) { 'eigen' => 'Eigenes Vorschaubild.', 'datei' => 'Vorschaubild aus der Datei des Mediums.', diff --git a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php index c733a5c..3b0a512 100644 --- a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php @@ -589,7 +589,7 @@ private function viewerData(): array && $element->output_class === 'text' && $shown->status !== ContentVersionStatus::Gesperrt, 'bodyCommitted' => $committed, - 'pictureUrl' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path), + 'pictureUrl' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at), 'pictureCaption' => $this->pictureCaption($element), ]; } @@ -1076,7 +1076,7 @@ public function previewHtml(): string 'kind' => PublicMaterialReader::outputLabel((string) $element->output_class), 'hide_status' => true, 'image' => trim($this->thumbnailAlt) !== '' ? trim($this->thumbnailAlt) : $title, - 'image_url' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path), + 'image_url' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at), 'error' => 'Vorschau der Kartenform. Ob jemand sie öffnen darf, entscheidet die Lizenz.', ], ]); diff --git a/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php b/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php index a8af291..a649584 100644 --- a/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php +++ b/app/Filament/Resources/LicenseArticles/Pages/ListLicenseArticles.php @@ -108,7 +108,7 @@ protected function catalogRows(): array 'titel' => $title, 'meta' => 'Lizenzartikel · '.$article->code.(filled($article->product_line) ? ' · '.$article->product_line : ''), 'text' => trim((string) ($article->teaser ?: $article->summary)), - 'bild' => $cover !== null ? ThumbnailRef::url('editorial.card', 'element', $cover->id, $cover->thumbnail_path) : null, + 'bild' => $cover !== null ? ThumbnailRef::url('editorial.card', 'element', $cover->id, $cover->thumbnail_path, 'klein', $cover->updated_at) : null, 'symbol' => 'dokument', 'url' => $url, 'chips' => $chips, diff --git a/app/Filament/Support/EditorialCatalog.php b/app/Filament/Support/EditorialCatalog.php index 2d5eef5..c25c364 100644 --- a/app/Filament/Support/EditorialCatalog.php +++ b/app/Filament/Support/EditorialCatalog.php @@ -18,12 +18,14 @@ use App\Domain\Catalog\LicenseArticle; use App\Domain\Catalog\OfferStatus; use App\Domain\Cms\Catalog\PublicMaterialReader; +use App\Domain\Media\ThumbnailRef; use App\Filament\Resources\Combinations\CombinationResource; use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Resources\Courses\CourseResource; use App\Filament\Resources\Documents\DocumentResource; use App\Filament\Resources\Exercises\ExerciseResource; use App\Filament\Resources\Practices\PracticeResource; +use Carbon\CarbonInterface; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; @@ -115,7 +117,7 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all 'usage_note' => (string) ($element->usage_note ?? ''), 'license_note' => (string) ($element->license_note ?? ''), 'tone' => $this->tone((string) $element->output_class, $kind), - 'image' => $this->cardUrl('element', $element->id, $element->thumbnail_path), + 'image' => $this->cardUrl('element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at), 'version_label' => match ($version->status) { ContentVersionStatus::Entwurf => 'Entwurf', ContentVersionStatus::Gesperrt => 'deaktiviert', @@ -163,7 +165,7 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all 'kind' => $kind, 'summary' => FormattedText::plain((string) ($composition->summary ?? '')), 'tone' => $this->tone('', $kind), - 'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path), + 'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path, 'klein', $composition->updated_at), 'version_label' => $version->status === ContentVersionStatus::Gesperrt ? 'deaktiviert' : 'Fassung '.$version->number, @@ -198,7 +200,7 @@ private function draftCompositionRow(int $compositionId, int $exceptCompositionI 'kind' => $kind, 'summary' => FormattedText::plain((string) ($composition->summary ?? '')), 'tone' => $this->tone('', $kind), - 'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path), + 'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path, 'klein', $composition->updated_at), 'version_label' => 'Entwurf', 'identity' => 'zusammenstellung:'.$composition->id, 'open_url' => route('editorial.draft-preview', ['composition' => $composition]), @@ -524,7 +526,7 @@ private function rowForPresentationMedium(int $id): ?array 'license_note' => (string) ($element->license_note ?? ''), 'tone' => $this->tone((string) $element->output_class, $kind), 'image' => $element->output_class === 'bild' - ? $this->cardUrl('element', $element->id, $element->thumbnail_path) + ? $this->cardUrl('element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at) : null, 'version_label' => 'Ohne Inhaltsfassung', 'committed' => false, @@ -548,13 +550,9 @@ public function tone(string $outputClass, string $kindLabel): string }; } - public function cardUrl(string $kind, int $id, ?string $path): ?string + public function cardUrl(string $kind, int $id, ?string $path, ?string $size = null, CarbonInterface|int|string|null $version = null): ?string { - if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) { - return null; - } - - return route('editorial.card', ['kind' => $kind, 'subject' => $id]); + return ThumbnailRef::url('editorial.card', $kind, $id, $path, $size, $version); } /** @@ -891,7 +889,7 @@ public function filmPictures(array $members): array continue; } - $image = $this->cardUrl('element', $element->id, $element->thumbnail_path); + $image = $this->cardUrl('element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at); if ($image === null || isset($pictures[$element->id])) { continue; @@ -933,7 +931,7 @@ public function mediaPictures(string $query): array ->limit(12) ->get() ->map(function (ContentElement $element): ?array { - $image = $this->cardUrl('element', $element->id, $element->thumbnail_path); + $image = $this->cardUrl('element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at); if ($image === null) { return null; @@ -957,7 +955,7 @@ public function mediaPictures(string $query): array */ public function cover(Composition $composition, array $members): array { - $own = $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path); + $own = $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path, 'mittel', $composition->updated_at); if ($own !== null) { return ['url' => $own, 'note' => null, 'own' => true]; @@ -970,7 +968,7 @@ public function cover(Composition $composition, array $members): array } return [ - 'url' => $this->cardUrl($picture['kind'], $picture['subject'], 'vorschau/gesetzt'), + 'url' => $this->cardUrl($picture['kind'], $picture['subject'], 'vorschau/gesetzt', 'mittel'), 'note' => $picture['note'], 'own' => false, ]; diff --git a/app/Filament/Support/MediaLibrary.php b/app/Filament/Support/MediaLibrary.php index 9c4d4a9..a4da9ed 100644 --- a/app/Filament/Support/MediaLibrary.php +++ b/app/Filament/Support/MediaLibrary.php @@ -553,7 +553,7 @@ private function card(ContentElement $element, array $portrait, array $uses, arr 'description' => $description === '' ? null : $description, 'usageNote' => $usageNote === '' ? null : $usageNote, 'licenseNote' => $licenseNote === '' ? null : $licenseNote, - 'image' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path), + 'image' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at), 'imageAlt' => trim((string) ($element->thumbnail_alt ?: $element->working_title)), 'imageNote' => $this->imageNote($element), 'presentation' => $this->isPresentationMedium($element, $portrait['versionCount']), diff --git a/app/Http/Controllers/Concerns/ServesImages.php b/app/Http/Controllers/Concerns/ServesImages.php new file mode 100644 index 0000000..34f3099 --- /dev/null +++ b/app/Http/Controllers/Concerns/ServesImages.php @@ -0,0 +1,62 @@ + 'inline', + 'X-Content-Type-Options' => 'nosniff', + ]; + $response = $disk->response($path, null, $headers); + $modified = (int) $disk->lastModified($path); + $size = (int) $disk->size($path); + + $response->setEtag(md5($path.'|'.$modified.'|'.$size)); + $response->setLastModified(Carbon::createFromTimestamp($modified)); + + if ($versioned) { + $response->headers->set('Cache-Control', $scope.', max-age=31536000, immutable'); + } else { + $response->headers->set('Cache-Control', $scope.', max-age=0, must-revalidate'); + } + + $response->isNotModified($request); + + return $response; + } + + /** Pfad der angefragten Größe (`?g=klein|mittel`), sonst die Hauptdatei. */ + protected function imagePathFor(Request $request, string $diskName, string $path): string + { + $size = $request->query('g'); + + return ImageVariants::resolve(Storage::disk($diskName), $path, is_string($size) ? $size : null); + } + + /** `?v=` ist da und eine einfache Zahl (Zeitstempel). */ + protected function hasImageVersion(Request $request): bool + { + $version = $request->query('v'); + + return is_string($version) && preg_match('/^[0-9]{1,12}$/', $version) === 1; + } +} diff --git a/app/Http/Controllers/EditorialPreviewController.php b/app/Http/Controllers/EditorialPreviewController.php index 8f2c406..c7dd402 100644 --- a/app/Http/Controllers/EditorialPreviewController.php +++ b/app/Http/Controllers/EditorialPreviewController.php @@ -12,15 +12,18 @@ use App\Domain\Identity\StaffRole; use App\Domain\Media\ThumbnailDeriver; use App\Filament\Support\EditorialCatalog; +use App\Http\Controllers\Concerns\ServesImages; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\Storage; use Illuminate\View\View; -use Symfony\Component\HttpFoundation\StreamedResponse; +use Symfony\Component\HttpFoundation\Response as SymfonyResponse; class EditorialPreviewController extends Controller { + use ServesImages; + public function show(Composition $composition, ?CompositionVersion $version = null): View { $this->authorizeStaff(); @@ -104,7 +107,7 @@ public function draft(Composition $composition): View ); } - public function card(string $kind, int $subject): StreamedResponse + public function card(Request $request, string $kind, int $subject): SymfonyResponse { $this->authorizeStaff(); abort_unless(in_array($kind, ['element', 'komposition'], true), 404); @@ -116,7 +119,13 @@ public function card(string $kind, int $subject): StreamedResponse $disk = Storage::disk('media_derived'); abort_unless($disk->exists($path), 404); - return $disk->response($path); + return $this->respondWithImage( + $request, + 'media_derived', + $this->imagePathFor($request, 'media_derived', $path), + 'private', + $this->hasImageVersion($request), + ); } /** diff --git a/app/Http/Controllers/Member/LibraryController.php b/app/Http/Controllers/Member/LibraryController.php index 3c77590..4c1d845 100644 --- a/app/Http/Controllers/Member/LibraryController.php +++ b/app/Http/Controllers/Member/LibraryController.php @@ -20,6 +20,7 @@ use App\Domain\Media\FilmPlayback; use App\Domain\Media\HlsPlaylist; use App\Domain\Media\MediaRendition; +use App\Http\Controllers\Concerns\ServesImages; use App\Http\Controllers\Controller; use App\Http\CourseOutline; use App\Http\LibraryCatalog; @@ -32,10 +33,13 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Storage; use Illuminate\View\View; +use Symfony\Component\HttpFoundation\Response as SymfonyResponse; use Symfony\Component\HttpFoundation\StreamedResponse; class LibraryController extends Controller { + use ServesImages; + /** Inhaltsarten der Bibliothek (Schlüssel der Adresse und des Filters). */ public const TYPES = [ 'programm' => 'Programme', @@ -361,7 +365,7 @@ public function rendition( return $disk->response($datei, basename($datei), ['Content-Disposition' => 'inline']); } - public function thumbnail(Request $request, string $kind, int $subject): StreamedResponse + public function thumbnail(Request $request, string $kind, int $subject): SymfonyResponse { abort_unless(in_array($kind, ['komposition', 'element'], true), 404); $model = $kind === 'komposition' @@ -373,7 +377,13 @@ public function thumbnail(Request $request, string $kind, int $subject): Streame $disk = Storage::disk('media_derived'); abort_unless($disk->exists($path), 404); - return $disk->response($path); + return $this->respondWithImage( + $request, + 'media_derived', + $this->imagePathFor($request, 'media_derived', $path), + 'private', + $this->hasImageVersion($request), + ); } /** diff --git a/app/Http/Controllers/WebsiteMediaController.php b/app/Http/Controllers/WebsiteMediaController.php index df85a7c..c8aa0a6 100644 --- a/app/Http/Controllers/WebsiteMediaController.php +++ b/app/Http/Controllers/WebsiteMediaController.php @@ -3,16 +3,22 @@ namespace App\Http\Controllers; use App\Domain\Catalog\ContentElement; +use App\Domain\Media\ImageVariants; use App\Domain\Media\WebsiteMedia; use App\Http\Controllers\Concerns\ServesByteRanges; +use App\Http\Controllers\Concerns\ServesImages; +use App\Jobs\DeriveWebsiteVariants; use Illuminate\Http\Request; -use Symfony\Component\HttpFoundation\StreamedResponse; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Storage; +use Symfony\Component\HttpFoundation\Response; class WebsiteMediaController extends Controller { use ServesByteRanges; + use ServesImages; - public function show(Request $request, ContentElement $element, WebsiteMedia $media): StreamedResponse + public function show(Request $request, ContentElement $element, WebsiteMedia $media): Response { $presentation = $media->present($element); abort_if($presentation === null, 404); @@ -20,6 +26,45 @@ public function show(Request $request, ContentElement $element, WebsiteMedia $me $path = $element->website_public_path; abort_if(! is_string($path), 404); - return $this->respondWithRanges($request, 'media_public', $path, $presentation->kind !== 'bild'); + if ($presentation->kind !== 'bild') { + return $this->respondWithRanges($request, 'media_public', $path, true); + } + + $path = $this->widthPath($request, $element, $path); + // Die Adresse trägt den Zeitpunkt der Freigabe. Gilt er noch, ändert sich der Inhalt unter dieser Adresse nicht mehr + // (eine neue Freigabe liefert eine neue Adresse); eine veraltete Adresse wird nur kurz vorgehalten und geprüft. + $current = $this->hasImageVersion($request) + && (int) $request->query('v') === $element->website_released_at?->getTimestamp(); + + return $this->respondWithImage($request, 'media_public', $path, 'public', $current); + } + + /** + * Die angefragte Breite (`?w=640|1280|1920`), sonst die volle Datei. Fehlt die Breite noch, geht die volle Datei hinaus, + * und die Warteschlange legt die Breiten an (höchstens einmal je Stunde und Bild; der Web-Prozess schreibt nie). + */ + private function widthPath(Request $request, ContentElement $element, string $path): string + { + $width = $request->query('w'); + + if (! is_string($width) || preg_match('/^[0-9]{3,4}$/', $width) !== 1 || ! ImageVariants::isPublicWidth((int) $width)) { + return $path; + } + + if (! in_array(strtolower(pathinfo($path, PATHINFO_EXTENSION)), ['jpg', 'jpeg'], true)) { + return $path; + } + + $variant = ImageVariants::publicPath($path, (int) $width); + + if (Storage::disk('media_public')->exists($variant)) { + return $variant; + } + + if (Cache::add('bildvarianten.website.'.$element->id, true, now()->addHour())) { + DeriveWebsiteVariants::dispatch($element->id); + } + + return $path; } } diff --git a/app/Http/LibraryCatalog.php b/app/Http/LibraryCatalog.php index 5df9145..45487a8 100644 --- a/app/Http/LibraryCatalog.php +++ b/app/Http/LibraryCatalog.php @@ -92,6 +92,7 @@ public function index(User $user): array 'image_url' => $picture === null ? null : route('member.thumbnail', [ 'kind' => $picture['kind'], 'subject' => $picture['subject'], + 'g' => 'mittel', ]), 'url' => route('member.program', $composition), ]; @@ -113,7 +114,7 @@ public function index(User $user): array : ($element?->id !== null ? 'element-'.$element->id : 'artikel-'.$article->id); $subject = $element ?? $composition ?? $article; $text = $element !== null ? $this->text($element) : null; - $imageUrl = $element === null ? null : ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path); + $imageUrl = $element === null ? null : ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at); $media[$key] = ($media[$key] ?? []) + [ 'used_in' => [], 'versions' => [], @@ -376,7 +377,7 @@ private function present(User $user, StructureNode $node, bool $full, int $rootI } if ($view !== null && $element !== null) { - $poster = ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path); + $poster = ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at); } } diff --git a/app/Http/MemberLicenses.php b/app/Http/MemberLicenses.php index 9ff1a54..6a057b3 100644 --- a/app/Http/MemberLicenses.php +++ b/app/Http/MemberLicenses.php @@ -129,8 +129,8 @@ private function entry(User $user, Grant $grant): array if ($grant->status === GrantStatus::Aktiv) { $imageUrl = $composition !== null - ? ThumbnailRef::url('member.thumbnail', 'komposition', $composition->id, $composition->thumbnail_path) - : ($element === null ? null : ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path)); + ? ThumbnailRef::url('member.thumbnail', 'komposition', $composition->id, $composition->thumbnail_path, 'klein', $composition->updated_at) + : ($element === null ? null : ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at)); } $title = $composition !== null diff --git a/app/Jobs/DeriveImageVariants.php b/app/Jobs/DeriveImageVariants.php new file mode 100644 index 0000000..1a21cfa --- /dev/null +++ b/app/Jobs/DeriveImageVariants.php @@ -0,0 +1,28 @@ +path) !== 1 || str_contains($this->path, '..')) { + return; + } + + ImageVariants::generate(Storage::disk('media_derived'), $this->path); + } +} diff --git a/app/Jobs/DeriveWebsiteVariants.php b/app/Jobs/DeriveWebsiteVariants.php new file mode 100644 index 0000000..c4c74f1 --- /dev/null +++ b/app/Jobs/DeriveWebsiteVariants.php @@ -0,0 +1,38 @@ +find($this->elementId); + + if (! $element instanceof ContentElement || $element->output_class !== 'bild' || $element->website_released_at === null) { + return; + } + + $path = $element->website_public_path; + + if (! is_string($path) || preg_match('#^website/'.$element->id.'/datei\.[a-z0-9]+$#', $path) !== 1) { + return; + } + + $disk = Storage::disk('media_public'); + ImageVariants::generatePublic($disk, $disk, $path, $path); + } +} diff --git a/app/Jobs/PublishWebsiteMedia.php b/app/Jobs/PublishWebsiteMedia.php index 7b28b38..b306c59 100644 --- a/app/Jobs/PublishWebsiteMedia.php +++ b/app/Jobs/PublishWebsiteMedia.php @@ -4,6 +4,7 @@ use App\Domain\Catalog\ContentElement; use App\Domain\Catalog\IdentityChange; +use App\Domain\Media\ImageVariants; use App\Domain\Media\WebsiteRelease; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; @@ -51,6 +52,12 @@ public function handle(WebsiteRelease $release): void if (is_string($previous) && $previous !== $target && str_starts_with($previous, 'website/'.$element->id.'/')) { Storage::disk('media_public')->delete($previous); + ImageVariants::deletePublic(Storage::disk('media_public'), $previous); + } + + if ($element->output_class === 'bild') { + // Breiten für die Website neben der Hauptdatei; ohne sie liefert die Website immer die volle Datei. + ImageVariants::generatePublic(Storage::disk('media_derived'), Storage::disk('media_public'), $derived, $target); } $this->mark($element, $element->website_released_at?->toIso8601String(), now()->toIso8601String()); @@ -69,6 +76,8 @@ private function deletePublicFile(ContentElement $element): void } Storage::disk('media_public')->delete($path); + // Auch die Breiten: Sonst bliebe ein zurückgenommenes Bild unter dem Namen einer Fassung erreichbar. + ImageVariants::deletePublic(Storage::disk('media_public'), $path); } private function mark(ContentElement $element, ?string $before, ?string $after): void diff --git a/docs/architektur/12_Entscheidungsprotokoll_ADR.md b/docs/architektur/12_Entscheidungsprotokoll_ADR.md index c456a1a..4a91ea6 100644 --- a/docs/architektur/12_Entscheidungsprotokoll_ADR.md +++ b/docs/architektur/12_Entscheidungsprotokoll_ADR.md @@ -943,3 +943,20 @@ ## ADR-62 – Kommunikation: Formularansicht mit Ziehen und Ablegen statt Builde **Alternativen.** Filament-Builder mit besseren Blocktiteln (verworfen: bleibt eine aufklappbare Endlosliste ohne sichtbare Zugehörigkeit). Neue Datenstruktur mit verschachtelten Teilbereichen im Entwurf (ausgeschlossen: kein neues Datenmodell; die Zugehörigkeit steht schon als Feldgruppe im Katalog). Eigenes Ziehen ohne Bibliothek (verworfen: Berührung, Animation und Randfälle liefert SortableJS). **Folgen.** Keine Migration. Die Livewire-Tests des Editors wurden bewusst auf den Baumtext umgestellt (der Builder entfällt). Rückfall auf ADR-61: Der Entwurf bleibt gültig; die ältere Ansicht liest ihn wieder. Das Ziehen bietet auf Berührungsbildschirmen SortableJS-Standardverhalten, wurde dort aber nicht geprüft. **Quelle.** Rückmeldung von Lars vom 28.11.2026 zur Bedienung des Formular-Editors; ADR-61. + +## ADR-63 – Bildfassungen: Thumbnail, Web und Vollauflösung + +**Status am 28.11.2026:** Umgesetzt auf `feature/bildvarianten`; Messung und Abnahme auf `luf-test` offen. Beschreibung: `docs/architektur/bildvarianten.md`. +**Kontext.** Medienauswahl, Contentmanager und Listen luden für jedes Kachelbild dieselbe Datei wie die Vorschau (bei Bildern bis 2400 px), die Website lieferte immer die volle Fassung. Jedes Bild war eine PHP-Anfrage mit Sitzung (`Set-Cookie`, Zeile in `sessions`) und `Cache-Control: no-cache, private`; der Browser behielt nichts. Gemessen auf `luf-test`: 120 bis 260 KB je Vorschaubild, ein PNG mit 1,2 MB als Website-Datei. +**Entscheidung.** +- **Drei Stufen je Bild.** Verwaltung: `klein` (360 px), `mittel` (960 px) und die volle Datei (`thumbnail_path`, unverändert). Website: Breiten 640, 1280 und 1920 px neben der vollen Datei (`website/{id}/datei-{breite}.jpg`). Fassungen entstehen nur, wenn die Quelle breiter ist; nie vergrößert. +- **Namensregel statt Spalte.** `element-12-klein.jpg` liegt neben `element-12.jpg`. Keine Migration. Fehlt eine Fassung, gilt die nächstgrößere Datei; Bestand bricht nicht. +- **Geschrieben wird nur in der Warteschlange** (`ThumbnailDeriver`, `PresentationFile::place`, `PublishWebsiteMedia`). Der Web-Prozess liest nur. Bestand ohne Fassungen füllt sich selbst: Die Auslieferung nimmt die volle Datei und legt (höchstens einmal je Stunde und Bild) einen Auftrag `DeriveWebsiteVariants` an; `media:varianten` holt alles auf einmal nach, ohne Zugriff auf den Server. +- **Zwischenspeicherung.** Adressen tragen Größe (`g`) und Version (`v`, `updated_at` des Mediums bzw. Zeitpunkt der Freigabe). Mit Version: ein Jahr, `immutable` (`private` in der Verwaltung und im Mitgliederbereich, `public` auf der Website). Ohne Version: ETag und Last-Modified, `304` ohne Inhalt. Eine neue Ableitung setzt die Version (`touch`). +- **Website ohne Sitzung.** Die Route `website.media` läuft ohne Sitzung, Cookies und CSRF: keine Sitzungszeile, kein `Set-Cookie`, zwischenspeicherbar. +- **`srcset`** in Hero, Bild mit Text, Karten und Medienkarte; Abschnittshintergründe nehmen die Breite 1920. Nur JPEG-Quellen erhalten Breiten (PNG, GIF, WebP können Transparenz tragen). +- **Rücknahme** der Website-Freigabe löscht auch die Breiten. +- **Auswahl im CMS:** Die Optionsliste fragte je Eintrag das Medium dreimal ab; geladene Medien werden jetzt weitergereicht. +**Alternativen.** WebP (verworfen für jetzt: das Docker-Image baut GD ohne WebP; eigener Schritt mit Dockerfile-Änderung). Fassungen im Aufruf berechnen und zwischenspeichern (verworfen: der Web-Prozess darf nicht schreiben). Spalten für Fassungen (verworfen: Namensregel genügt, keine Migration). Statische Auslieferung durch den Webserver (verworfen: private Medien bleiben hinter der Berechtigung). +**Folgen.** Keine Migration. Tests mit festen Adressen der Website-Bilder wurden bewusst geändert (Adresse trägt `?v=`, Bild-Tags tragen `srcset`). Rückfall: Ein Stand ohne ADR-63 kennt `g`/`v` nicht und liefert die volle Datei; die Fassungsdateien bleiben liegen und stören nicht. Offen: EXIF-Drehung (Handyfotos), WebP. +**Quelle.** Rückmeldung von Lars vom 28.11.2026 zu den Ladezeiten von Medienauswahl, Contentmanager und Website. diff --git a/docs/architektur/bildvarianten.md b/docs/architektur/bildvarianten.md new file mode 100644 index 0000000..59851e1 --- /dev/null +++ b/docs/architektur/bildvarianten.md @@ -0,0 +1,42 @@ +# Bildfassungen (ADR-63) + +Stand 28.11.2026. Gilt für alle Bilder, die die Anwendung anzeigt: Vorschaubilder der Verwaltung (Medienauswahl, Listen, Karten, Aufbau), Bilder im CMS und auf der Website. + +## Stufen + +| Stufe | Wo | Breite | Verwendung | +|---|---|---|---| +| `klein` | `derived/vorschau/…-klein.jpg` | 360 px | Auswahl, Listen, Kacheln, Zeilen im Aufbau | +| `mittel` | `derived/vorschau/…-mittel.jpg` | 960 px | Detailansicht, Vorschau im Editor, Kartenbilder in Seitenvorschauen, Poster | +| voll | `derived/vorschau/element-N.jpg` (`thumbnail_path`) | Bilder bis 2400 px, sonst 640 px | Quelle für die Website-Freigabe | +| Website | `public/website/N/datei-{640,1280,1920}.jpg` | 640, 1280, 1920 | `srcset` von Hero, Bild mit Text, Karten; Hintergrund 1920 | +| Website voll | `public/website/N/datei.jpg` | bis 2400 px | Rückfall und `src` | +| Original | `originals/…`, `derived/inhalte/…` | unverändert | nur Hintergrundverarbeitung, nie ausgeliefert | + +Die Fassungen heißen wie die Hauptdatei mit Suffix (`ImageVariants::path`). Es gibt keine Spalte. **Fehlt eine Fassung, gilt die nächstgrößere Datei.** + +## Wer schreibt + +Nur die Warteschlange (`queue`); der Web-Prozess liest: + +- `ThumbnailDeriver::still()` und `frame()` (jede Ableitung eines Vorschaubildes) und `PresentationFile::place()` rufen `ImageVariants::generate`. +- `PublishWebsiteMedia` (Freigabe) ruft `ImageVariants::generatePublic`; Rücknahme und Ersatz löschen die Breiten. +- `DeriveImageVariants` und `DeriveWebsiteVariants` füllen Bestand nach. Sie werden vom Befehl `php artisan media:varianten` (`--now`, `--pretend`) oder von der Auslieferung angestoßen, wenn eine Breite fehlt (höchstens einmal je Stunde und Bild). + +Eine Fassung entsteht nur, wenn die Quelle breiter ist; sonst wird eine ältere gelöscht. Fassungen sind JPEG (Qualität 80, progressiv), transparente Flächen werden weiß. Website-Breiten gibt es nur für JPEG-Quellen. + +## Auslieferung + +- **Verwaltung** `GET /redaktion/karte/{kind}/{subject}?g=klein|mittel&v=…` (nur angemeldete Redaktion) und **Mitgliederbereich** `member.thumbnail` mit denselben Parametern (Berechtigung unverändert). +- **Website** `GET /website-medien/{id}?w=640|1280|1920&v=…` (nur freigegebene Medien). +- `ThumbnailRef::url(route, kind, id, path, size, version)` und `EditorialCatalog::cardUrl` bauen die Adressen. Wer ein Bild neu anzeigt, wählt `klein` für alles unter etwa 180 px Anzeigebreite, sonst `mittel`, und übergibt `updated_at` als Version. +- Mit `v` in der Adresse: `Cache-Control: private|public, max-age=31536000, immutable`. Ohne `v` oder bei veralteter Website-Version: `max-age=0, must-revalidate` mit ETag und Last-Modified, `304` bei unverändertem Bild. +- Die Website-Route läuft ohne Sitzung und Cookies. + +## Nachprüfen + +Auf dem Server nur lesend: `ls derived/vorschau | grep -- -klein`, `ls public/website/*/`. Im Browser: Netzwerk-Reiter, `Cache-Control` und Größe der Bilder; zweiter Aufruf der Medienauswahl lädt die Bilder aus dem Browser-Cache. + +## Nicht enthalten + +EXIF-Drehung von Handyfotos (bisher nicht beachtet), WebP/AVIF (das Image baut GD ohne WebP), Fassungen für Film-Standbilder über 640 px. diff --git a/resources/views/components/vw/eintrag.blade.php b/resources/views/components/vw/eintrag.blade.php index 0164ec3..30787f9 100644 --- a/resources/views/components/vw/eintrag.blade.php +++ b/resources/views/components/vw/eintrag.blade.php @@ -17,7 +17,7 @@ <{{ $as }} {{ $attributes->class('vw-eintrag') }}> @if (filled($bild)) - {{ $bildAlt }} + {{ $bildAlt }} @else @include('filament.verwaltung.icon', ['name' => $symbol])@if (filled($bildFehlt)){{ $bildFehlt }}@endif @endif diff --git a/resources/views/content/player.blade.php b/resources/views/content/player.blade.php index 5697bff..8bb276e 100644 --- a/resources/views/content/player.blade.php +++ b/resources/views/content/player.blade.php @@ -1,7 +1,7 @@ @php $metadata = is_array($version->metadata) ? $version->metadata : []; $class = $version->element->output_class; - $poster = \App\Domain\Media\ThumbnailRef::url('editorial.card', 'element', $version->element->id, $version->element->thumbnail_path); + $poster = \App\Domain\Media\ThumbnailRef::url('editorial.card', 'element', $version->element->id, $version->element->thumbnail_path, 'mittel', $version->element->updated_at); $playback = $class === 'film' ? app(\App\Http\Controllers\ContentPreviewController::class)->playback($version) : null; @endphp diff --git a/resources/views/filament/verwaltung/aufbau.blade.php b/resources/views/filament/verwaltung/aufbau.blade.php index cda6acf..96c9b3a 100644 --- a/resources/views/filament/verwaltung/aufbau.blade.php +++ b/resources/views/filament/verwaltung/aufbau.blade.php @@ -47,7 +47,7 @@ x-on:keydown.alt.arrow-down.prevent="$wire.movePart({{ $index }}, 1)"> @if (! empty($member['image'])) - + @else @include('filament.verwaltung.icon', ['name' => $symbol($member['tone'] ?? null)]) @endif @@ -70,7 +70,7 @@ @forelse ($kinder as $kind)
- @if (! empty($kind['image']))@else@include('filament.verwaltung.icon', ['name' => $symbol($kind['tone'])])@endif + @if (! empty($kind['image']))@else@include('filament.verwaltung.icon', ['name' => $symbol($kind['tone'])])@endif {{ $kind['title'] }}
{{ $kind['kind'] }}@if ($kind['role'] !== '') · {{ $kind['role'] }}@endif
diff --git a/resources/views/filament/verwaltung/praesentation.blade.php b/resources/views/filament/verwaltung/praesentation.blade.php index 791ab80..bfe45fc 100644 --- a/resources/views/filament/verwaltung/praesentation.blade.php +++ b/resources/views/filament/verwaltung/praesentation.blade.php @@ -68,7 +68,7 @@ @endunless @if (! empty($row['image'])) - + @else @include('filament.verwaltung.icon', ['name' => $symbol($row['output'])]) @endif diff --git a/resources/views/member/article.blade.php b/resources/views/member/article.blade.php index 31432bb..38fc077 100644 --- a/resources/views/member/article.blade.php +++ b/resources/views/member/article.blade.php @@ -34,7 +34,7 @@
@include('content.video', [ 'playback' => ['mode' => $entry['playback'] ?? 'file', 'url' => $entry['url']], - 'poster' => \App\Domain\Media\ThumbnailRef::url('member.thumbnail', 'element', $entry['version']->element->id, $entry['version']->element->thumbnail_path), + 'poster' => \App\Domain\Media\ThumbnailRef::url('member.thumbnail', 'element', $entry['version']->element->id, $entry['version']->element->thumbnail_path, 'mittel', $entry['version']->element->updated_at), ])
diff --git a/resources/views/member/program.blade.php b/resources/views/member/program.blade.php index 1db9528..8eba893 100644 --- a/resources/views/member/program.blade.php +++ b/resources/views/member/program.blade.php @@ -32,7 +32,7 @@
@if ($picture) - {{ $picture['alt'] ?: '' }} + {{ $picture['alt'] ?: '' }} @else @endif diff --git a/resources/views/widgets/cards.blade.php b/resources/views/widgets/cards.blade.php index aa6753b..9fa4a18 100644 --- a/resources/views/widgets/cards.blade.php +++ b/resources/views/widgets/cards.blade.php @@ -30,7 +30,7 @@ ])> @if ($item['imageUrl'])
- +
@endif
diff --git a/resources/views/widgets/hero.blade.php b/resources/views/widgets/hero.blade.php index 2e2cce2..e6b7ea7 100644 --- a/resources/views/widgets/hero.blade.php +++ b/resources/views/widgets/hero.blade.php @@ -21,7 +21,7 @@ style="--lf-hero-focus-x: {{ $focus['x'] }}%; --lf-hero-focus-y: {{ $focus['y'] }}%" @if ($videoUrl !== null) data-hero-video data-clip-src="{{ $videoUrl }}" data-clip-title="{{ $videoTitle }}" @endif> @if ($layout === 'photo-split' && $imageUrl) - {{ $imageAlt ?? '' }} + {{ $imageAlt ?? '' }} @endif @if ($videoUrl !== null) diff --git a/resources/views/widgets/image_text.blade.php b/resources/views/widgets/image_text.blade.php index b7a5484..afd7aae 100644 --- a/resources/views/widgets/image_text.blade.php +++ b/resources/views/widgets/image_text.blade.php @@ -56,7 +56,7 @@ @endif @if ($imageUrl)
- {{ $imageAlt ?? '' }} + {{ $imageAlt ?? '' }} @include('widgets.partials.card-clip')
@endif diff --git a/resources/views/widgets/premium_card.blade.php b/resources/views/widgets/premium_card.blade.php index 02a94d8..81bab31 100644 --- a/resources/views/widgets/premium_card.blade.php +++ b/resources/views/widgets/premium_card.blade.php @@ -52,7 +52,7 @@ ]) style="--pc-focus-x: {{ $focus['x'] }}%; --pc-focus-y: {{ $focus['y'] }}%"> @if ($imageUrl !== null || $libraryImage !== null)
- {{ $imageUrl !== null ? $alt : '' }} + {{ $imageUrl !== null ? $alt : '' }} @include('widgets.partials.card-clip') @if ($show['kind'] && $subject->badge !== null && empty($bare)) {{ $subject->badge }} diff --git a/routes/web.php b/routes/web.php index de208cb..ef162cf 100644 --- a/routes/web.php +++ b/routes/web.php @@ -28,7 +28,13 @@ use App\Http\Controllers\WebsiteMediaController; use App\Http\Middleware\EnsureCheckoutOpen; use App\Http\Middleware\EnsureShopVisible; +use App\Http\Middleware\SanitizeIntendedUrl; +use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; +use Illuminate\Cookie\Middleware\EncryptCookies; +use Illuminate\Foundation\Http\Middleware\PreventRequestForgery; +use Illuminate\Session\Middleware\StartSession; use Illuminate\Support\Facades\Route; +use Illuminate\View\Middleware\ShareErrorsFromSession; Route::get('/', [PageController::class, 'home'])->name('home'); Route::get('/sitemap.xml', [PageController::class, 'sitemap'])->name('sitemap'); @@ -38,7 +44,19 @@ Route::get('/pakete/{bundle}', [PublicCatalogController::class, 'package'])->whereNumber('bundle')->name('public.package'); Route::get('/themen/{slug}', [ThemeController::class, 'show'])->name('theme')->where('slug', '[a-z0-9]+(?:-[a-z0-9]+)*'); Route::get('/medien/{path}', [PublicMediaController::class, 'show'])->where('path', '.*')->name('media.public'); -Route::get('/website-medien/{element}', [WebsiteMediaController::class, 'show'])->whereNumber('element')->name('website.media'); +// Öffentliche Medien brauchen weder Sitzung noch Cookies: Ohne sie legt die Anfrage keine Sitzungszeile an, setzt kein Cookie +// und darf von Browsern und Zwischenspeichern behalten werden. +Route::get('/website-medien/{element}', [WebsiteMediaController::class, 'show']) + ->whereNumber('element') + ->withoutMiddleware([ + EncryptCookies::class, + AddQueuedCookiesToResponse::class, + StartSession::class, + ShareErrorsFromSession::class, + PreventRequestForgery::class, + SanitizeIntendedUrl::class, + ]) + ->name('website.media'); // Schalter 1 (Shop sichtbar): Übersicht, Produktseiten und die Hinweisseite. Schalter 2 (Checkout offen): Warenkorb und // Kasse; ist der Shop nur sichtbar, führen sie auf die Hinweisseite (EnsureCheckoutOpen). diff --git a/tests/Feature/BildvariantenTest.php b/tests/Feature/BildvariantenTest.php new file mode 100644 index 0000000..89858ba --- /dev/null +++ b/tests/Feature/BildvariantenTest.php @@ -0,0 +1,338 @@ +put('vorschau/element-1.jpg', $this->jpeg(2000, 1000)); + + $written = ImageVariants::generate($disk, 'vorschau/element-1.jpg'); + + $this->assertSame(['vorschau/element-1-klein.jpg', 'vorschau/element-1-mittel.jpg'], $written); + $this->assertSame([360, 180], array_slice(getimagesizefromstring($disk->get('vorschau/element-1-klein.jpg')), 0, 2)); + $this->assertSame([960, 480], array_slice(getimagesizefromstring($disk->get('vorschau/element-1-mittel.jpg')), 0, 2)); + $this->assertLessThan(strlen($disk->get('vorschau/element-1.jpg')), strlen($disk->get('vorschau/element-1-klein.jpg'))); + + $disk->put('vorschau/element-2.jpg', $this->jpeg(640, 320)); + $this->assertSame(['vorschau/element-2-klein.jpg'], ImageVariants::generate($disk, 'vorschau/element-2.jpg')); + $disk->assertMissing('vorschau/element-2-mittel.jpg'); + + // Wird die Hauptdatei durch ein kleineres Bild ersetzt, verschwindet die zu große Fassung. + $disk->put('vorschau/element-1.jpg', $this->jpeg(300, 150)); + ImageVariants::generate($disk, 'vorschau/element-1.jpg'); + $disk->assertMissing('vorschau/element-1-klein.jpg'); + $disk->assertMissing('vorschau/element-1-mittel.jpg'); + } + + public function test_unreadable_files_produce_no_variants_and_no_error(): void + { + $disk = Storage::disk('media_derived'); + $disk->put('vorschau/kaputt.jpg', 'kein-bild'); + + $this->assertSame([], ImageVariants::generate($disk, 'vorschau/kaputt.jpg')); + $this->assertSame([], ImageVariants::generate($disk, 'vorschau/fehlt.jpg')); + $this->assertSame('vorschau/kaputt.jpg', ImageVariants::resolve($disk, 'vorschau/kaputt.jpg', 'klein')); + $this->assertSame('vorschau/kaputt.jpg', ImageVariants::resolve($disk, 'vorschau/kaputt.jpg', '../x')); + } + + public function test_deriving_a_thumbnail_creates_the_variants_and_changes_the_version(): void + { + $element = app(ContentService::class)->createElement('bild', 'bild', 'Park'); + $version = app(ContentService::class)->publishElementVersion($element, null, ['file' => 'inhalte/park.jpg']); + Storage::disk('media_derived')->put('inhalte/park.jpg', $this->jpeg(3000, 1500)); + $this->assertNotNull($version); + + $before = now()->subDay(); + ContentElement::query()->whereKey($element->id)->update(['updated_at' => $before]); + + app(ThumbnailDeriver::class)->forElement($element->refresh()); + $element->refresh(); + + $this->assertSame('vorschau/element-'.$element->id.'.jpg', $element->thumbnail_path); + $this->assertSame(2400, getimagesizefromstring(Storage::disk('media_derived')->get($element->thumbnail_path))[0]); + Storage::disk('media_derived')->assertExists('vorschau/element-'.$element->id.'-klein.jpg'); + Storage::disk('media_derived')->assertExists('vorschau/element-'.$element->id.'-mittel.jpg'); + $this->assertTrue($element->updated_at->greaterThan($before), 'Die Version der Adresse ändert sich mit dem Bild.'); + } + + public function test_the_library_card_serves_the_requested_size_with_a_fallback_and_caches_by_version(): void + { + [$element, $disk] = $this->elementWithThumbnail(2000, 1000); + ImageVariants::generate($disk, $element->thumbnail_path); + $editor = User::factory()->redakteur()->create(); + + $klein = $this->actingAs($editor, 'staff')->get(route('editorial.card', ['kind' => 'element', 'subject' => $element->id, 'g' => 'klein'])); + $klein->assertOk(); + $this->assertSame($disk->get('vorschau/element-'.$element->id.'-klein.jpg'), $klein->streamedContent()); + $this->assertStringContainsString('must-revalidate', (string) $klein->headers->get('Cache-Control')); + $this->assertNotNull($klein->headers->get('ETag')); + + $voll = $this->actingAs($editor, 'staff')->get(route('editorial.card', ['kind' => 'element', 'subject' => $element->id])); + $this->assertSame($disk->get($element->thumbnail_path), $voll->streamedContent()); + + $versioned = $this->actingAs($editor, 'staff')->get(route('editorial.card', ['kind' => 'element', 'subject' => $element->id, 'g' => 'klein', 'v' => 1700000000])); + $cache = (string) $versioned->headers->get('Cache-Control'); + $this->assertStringContainsString('immutable', $cache); + $this->assertStringContainsString('private', $cache); + $this->assertStringContainsString('max-age=31536000', $cache); + + $again = $this->actingAs($editor, 'staff')->get( + route('editorial.card', ['kind' => 'element', 'subject' => $element->id, 'g' => 'klein']), + ['If-None-Match' => $klein->headers->get('ETag')], + ); + $again->assertStatus(304); + + $disk->delete('vorschau/element-'.$element->id.'-klein.jpg'); + $fallback = $this->actingAs($editor, 'staff')->get(route('editorial.card', ['kind' => 'element', 'subject' => $element->id, 'g' => 'klein'])); + $this->assertSame($disk->get($element->thumbnail_path), $fallback->streamedContent(), 'Ohne Fassung gilt die Hauptdatei.'); + } + + public function test_the_card_route_stays_closed_for_visitors_and_ignores_unknown_sizes(): void + { + [$element] = $this->elementWithThumbnail(800, 400); + + $this->get(route('editorial.card', ['kind' => 'element', 'subject' => $element->id, 'g' => 'klein']))->assertRedirect(); + + $editor = User::factory()->redakteur()->create(); + $this->actingAs($editor, 'staff') + ->get(route('editorial.card', ['kind' => 'element', 'subject' => $element->id, 'g' => '../../etc'])) + ->assertOk(); + } + + public function test_adresses_carry_size_and_version(): void + { + [$element] = $this->elementWithThumbnail(800, 400); + $element->refresh(); + $card = app(MediaLibrary::class)->cardFor($element, false); + + $this->assertStringContainsString('g=klein', (string) $card['image']); + $this->assertStringContainsString('v='.$element->updated_at->getTimestamp(), (string) $card['image']); + } + + public function test_a_released_image_gets_website_widths_and_serves_them_with_long_caching_and_no_cookie(): void + { + $medium = $this->releasedImage('Lara im Park', 2600, 1300); + $path = $medium->website_public_path; + $public = Storage::disk('media_public'); + + foreach ([640, 1280, 1920] as $width) { + $public->assertExists(ImageVariants::publicPath($path, $width)); + } + + $presentation = app(WebsiteMedia::class)->present($medium); + $this->assertNotNull($presentation); + $this->assertStringContainsString('v='.$medium->website_released_at->getTimestamp(), $presentation->url); + $this->assertStringContainsString('w=640', (string) $presentation->srcset); + $this->assertStringContainsString('1920w', (string) $presentation->srcset); + $this->assertStringContainsString('w=1920', $presentation->urlForWidth(1920)); + $this->assertSame($presentation->url, $presentation->urlForWidth(999)); + + $small = $this->get(route('website.media', ['element' => $medium, 'w' => 640, 'v' => $medium->website_released_at->getTimestamp()])); + $small->assertOk(); + $this->assertSame(640, getimagesizefromstring($small->streamedContent())[0]); + $cache = (string) $small->headers->get('Cache-Control'); + $this->assertStringContainsString('public', $cache); + $this->assertStringContainsString('immutable', $cache); + $this->assertEmpty($small->headers->getCookies(), 'Öffentliche Bilder setzen kein Cookie.'); + + $stale = $this->get(route('website.media', ['element' => $medium, 'v' => 1])); + $this->assertStringNotContainsString('immutable', (string) $stale->headers->get('Cache-Control')); + + $full = $this->get(route('website.media', ['element' => $medium])); + $this->assertSame(2400, getimagesizefromstring($full->streamedContent())[0]); + } + + public function test_a_released_image_without_widths_falls_back_to_the_full_file_and_asks_the_queue_once(): void + { + $medium = $this->releasedImage('Bestand', 2600, 1300); + $public = Storage::disk('media_public'); + + foreach ([640, 1280, 1920] as $width) { + $public->delete(ImageVariants::publicPath($medium->website_public_path, $width)); + } + + Queue::fake(); + + $first = $this->get(route('website.media', ['element' => $medium, 'w' => 1280])); + $this->assertSame(2400, getimagesizefromstring($first->streamedContent())[0]); + $this->get(route('website.media', ['element' => $medium, 'w' => 640]))->assertOk(); + + Queue::assertPushed(DeriveWebsiteVariants::class, 1); + + Queue::fake([]); + (new DeriveWebsiteVariants($medium->id))->handle(); + + foreach ([640, 1280, 1920] as $width) { + $public->assertExists(ImageVariants::publicPath($medium->website_public_path, $width)); + } + + $this->get(route('website.media', ['element' => $medium, 'w' => 4000]))->assertOk(); + $this->get(route('website.media', ['element' => $medium, 'w' => '../x']))->assertOk(); + } + + public function test_withdrawing_a_release_removes_the_widths_too(): void + { + $medium = $this->releasedImage('Zurück', 2600, 1300); + $public = Storage::disk('media_public'); + $widthUrl = route('website.media', ['element' => $medium, 'w' => 640]); + $this->get($widthUrl)->assertOk(); + + app(WebsiteRelease::class)->withdraw($medium); + + foreach ([640, 1280, 1920] as $width) { + $public->assertMissing('website/'.$medium->id.'/datei-'.$width.'.jpg'); + } + + $public->assertMissing('website/'.$medium->id.'/datei.jpg'); + $this->get($widthUrl)->assertNotFound(); + } + + public function test_images_with_transparency_formats_keep_no_widths(): void + { + $disk = Storage::disk('media_public'); + $disk->put('website/9/datei.png', $this->jpeg(2600, 1300)); + + $this->assertSame([], ImageVariants::generatePublic($disk, $disk, 'website/9/datei.png', 'website/9/datei.png')); + $disk->assertMissing('website/9/datei-640.jpg'); + } + + public function test_the_picker_options_do_not_query_per_entry(): void + { + foreach (range(1, 2) as $number) { + $this->releasedImage('Bild '.$number, 800, 400); + } + + DB::enableQueryLog(); + app(WebsiteImage::class)->options(); + $few = count(DB::getQueryLog()); + + foreach (range(3, 10) as $number) { + $this->releasedImage('Bild '.$number, 800, 400); + } + + DB::flushQueryLog(); + $options = app(WebsiteImage::class)->options(); + $many = count(DB::getQueryLog()); + + $this->assertCount(10, $options); + $this->assertSame($few, $many, 'Die Zahl der Abfragen wächst nicht mit der Zahl der Einträge.'); + } + + public function test_the_command_backfills_existing_images_through_the_queue(): void + { + [$element, $disk] = $this->elementWithThumbnail(2000, 1000); + $medium = $this->releasedImage('Alt', 2600, 1300); + $public = Storage::disk('media_public'); + + foreach ([640, 1280, 1920] as $width) { + $public->delete(ImageVariants::publicPath($medium->website_public_path, $width)); + } + + $disk->assertMissing('vorschau/element-'.$element->id.'-klein.jpg'); + + Queue::fake(); + $this->artisan('media:varianten')->assertSuccessful(); + Queue::assertPushed(DeriveImageVariants::class, fn (DeriveImageVariants $job): bool => $job->path === $element->thumbnail_path); + Queue::assertPushed(DeriveWebsiteVariants::class, fn (DeriveWebsiteVariants $job): bool => $job->elementId === $medium->id); + + } + + public function test_the_command_can_backfill_at_once(): void + { + [$element, $disk] = $this->elementWithThumbnail(2000, 1000); + $medium = $this->releasedImage('Alt', 2600, 1300); + $public = Storage::disk('media_public'); + $public->delete(ImageVariants::publicPath($medium->website_public_path, 640)); + + $this->artisan('media:varianten', ['--now' => true])->assertSuccessful(); + + $disk->assertExists('vorschau/element-'.$element->id.'-klein.jpg'); + $public->assertExists(ImageVariants::publicPath($medium->website_public_path, 640)); + } + + public function test_the_derive_job_refuses_foreign_paths(): void + { + $disk = Storage::disk('media_derived'); + $disk->put('inhalte/geheim.jpg', $this->jpeg(2000, 1000)); + + (new DeriveImageVariants('inhalte/geheim.jpg'))->handle(); + (new DeriveImageVariants('vorschau/../inhalte/geheim.jpg'))->handle(); + + $disk->assertMissing('inhalte/geheim-klein.jpg'); + } + + /** + * @return array{0: ContentElement, 1: Filesystem} + */ + private function elementWithThumbnail(int $width, int $height): array + { + $element = app(ContentService::class)->createElement('bild', 'bild', 'Bild '.Str::random(4)); + $element->forceFill(['thumbnail_path' => 'vorschau/element-'.$element->id.'.jpg'])->save(); + $disk = Storage::disk('media_derived'); + $disk->put($element->thumbnail_path, $this->jpeg($width, $height)); + + return [$element->refresh(), $disk]; + } + + private function releasedImage(string $title, int $width, int $height): ContentElement + { + $path = 'cms/'.Str::slug($title).'-'.Str::lower(Str::random(4)).'.jpg'; + Storage::disk('cms_incoming')->put($path, $this->jpeg($width, $height)); + + $element = app(WebsiteIntake::class)->acceptImage($path, $title, 'Foto: Lara und Felix', $title)->refresh(); + $this->assertNotNull($element->website_released_at, 'Das Bild ist freigegeben.'); + + return $element; + } + + private function jpeg(int $width, int $height): string + { + $image = imagecreatetruecolor($width, $height); + imagefill($image, 0, 0, (int) imagecolorallocate($image, 200, 120, 40)); + ob_start(); + imagejpeg($image); + + return (string) ob_get_clean(); + } +} diff --git a/tests/Feature/CmsCardTrailerTest.php b/tests/Feature/CmsCardTrailerTest.php index 3876f79..1b66ca0 100644 --- a/tests/Feature/CmsCardTrailerTest.php +++ b/tests/Feature/CmsCardTrailerTest.php @@ -80,7 +80,7 @@ public function test_the_trailer_lies_over_the_card_image_when_there_is_one(): v $this->publish('/trailer-bild', [$this->mediaCard($film, ['image' => $image->id])]); $card = $this->card($this->get('/trailer-bild')->assertOk()->getContent()); - $this->assertStringContainsString('assertStringContainsString('assertStringContainsString('data-clip-src="'.route('website.media', $trailer).'"', $card); $this->assertStringNotContainsString('lf-pc__visual--panel', $card); } diff --git a/tests/Feature/CmsImageTextMediaTest.php b/tests/Feature/CmsImageTextMediaTest.php index 8ee0bde..1860d35 100644 --- a/tests/Feature/CmsImageTextMediaTest.php +++ b/tests/Feature/CmsImageTextMediaTest.php @@ -88,7 +88,9 @@ public function test_an_image_can_stand_alone_without_any_text(): void $this->assertStringContainsString('lf-bt--without-text', $html); $this->assertStringNotContainsString('lf-bt__copy', $html, 'Ohne Text gibt es keine leere Textspalte.'); - $this->assertStringContainsString('Gruppe im ParkassertStringContainsString('assertStringContainsString('alt="Gruppe im Park"', $html); + $this->assertStringContainsString('srcset="', $html); $normalized = app(WidgetRegistry::class)->normalize($this->widget([], ['image' => $image->id])[0]['slots']); $this->assertSame($image->id, $normalized[0]['refs']['image']); diff --git a/tests/Feature/CmsPremiumCardsTest.php b/tests/Feature/CmsPremiumCardsTest.php index 2548646..f2082c3 100644 --- a/tests/Feature/CmsPremiumCardsTest.php +++ b/tests/Feature/CmsPremiumCardsTest.php @@ -202,7 +202,7 @@ public function test_media_card_is_public_only_as_part_of_a_public_program_and_n $preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent(); // Redaktionsvorschau: Filmstandbild der Bibliothek, deutlich als nicht öffentlich markiert, und Hinweise auf Fehlendes. - $this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'element', 'subject' => $film->id]).'"', $preview); + $this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'element', 'subject' => $film->id, 'g' => 'mittel']).'&v=', $preview); $this->assertStringContainsString('Bibliotheksbild · nur Vorschau', $preview); $this->assertStringContainsString('Das Vorschaubild der Bibliothek ist nicht für die Website freigegeben', $preview); $this->assertStringContainsString('Traineranleitung Abstand', $preview); @@ -242,7 +242,7 @@ public function test_draft_media_and_unreleased_compositions_can_be_prepared_but $this->assertStringContainsString('Das Programm hat keine Anzeigefreigabe.', $preview); $this->assertStringContainsString('Kinder erkennen eigene Grenzen.', $preview, 'Ohne Kurzbeschreibung zeigt die Karte das Lernziel.'); $this->assertStringContainsString('
  • Dauer 25 Min.
  • ', $preview); - $this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'komposition', 'subject' => $program->composition_id]).'"', $preview); + $this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'komposition', 'subject' => $program->composition_id, 'g' => 'mittel']).'&v=', $preview); $this->assertStringContainsString('Für Module gibt es noch keine öffentliche Seitenart', $preview); $this->assertStringNotContainsString(route('public.program', $module->composition_id), $preview, 'Module erhalten keinen künstlichen Link.'); } diff --git a/tests/Feature/CmsWebsiteMediaTest.php b/tests/Feature/CmsWebsiteMediaTest.php index 27c1493..a2aefd4 100644 --- a/tests/Feature/CmsWebsiteMediaTest.php +++ b/tests/Feature/CmsWebsiteMediaTest.php @@ -10,6 +10,7 @@ use App\Domain\Cms\WebsiteImageUsage; use App\Domain\Cms\Widgets\Support\WebsiteImage; use App\Domain\Media\WebsiteIntake; +use App\Domain\Media\WebsiteMedia; use App\Domain\Media\WebsiteMediaAlias; use App\Domain\Media\WebsiteRelease; use App\Filament\Resources\Pages\Pages\EditPage; @@ -47,7 +48,7 @@ protected function setUp(): void public function test_a_released_medium_is_shown_in_every_widget_through_the_website_route(): void { $medium = $this->releasedImage('Lara im Park', 'Lara sitzt auf einer Parkbank'); - $url = route('website.media', $medium); + $url = app(WebsiteMedia::class)->present($medium)->url; $revision = $this->publish('/medien-ueberall', [ ['layout' => 'u4', 'style' => ['background' => 'image', 'image' => $medium->id, 'overlay' => 'light'], 'slots' => [ @@ -63,7 +64,8 @@ public function test_a_released_medium_is_shown_in_every_widget_through_the_webs $this->assertSame($medium->id, $revision->sections[0]['style']['image']); $main = $this->main($this->get('/medien-ueberall')->assertOk()->getContent()); - $this->assertSame(4, substr_count($main, 'src="'.$url.'"'), 'Hintergrund, Einstieg, Bild und Text, Karte verwenden dasselbe Medium.'); + $this->assertSame(3, substr_count($main, 'src="'.$url.'"'), 'Einstieg, Bild und Text, Karte verwenden dasselbe Medium.'); + $this->assertSame(1, substr_count($main, 'src="'.$url.'&w=1920"'), 'Der Hintergrund nimmt dieselbe Datei in der Breite 1920.'); $this->assertStringContainsString('alt="Lara sitzt auf einer Parkbank"', $main, 'Alternativtext des Mediums.'); $this->assertStringContainsString('alt="Eigene Beschreibung"', $main, 'Abweichender Alternativtext im Widget.'); $this->assertStringNotContainsString('/redaktion/', $main); @@ -87,7 +89,7 @@ public function test_an_unreleased_medium_is_only_shown_in_the_preview_with_a_no $this->assertStringContainsString('lf-bt--without-image', $main); $preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent(); - $this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'element', 'subject' => $medium->id]).'"', $preview); + $this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'element', 'subject' => $medium->id, 'g' => 'mittel']).'&v=', $preview); $this->assertStringContainsString('Das gewählte Bild „Noch nicht freigegeben“ erscheint öffentlich nicht: Nicht für die Website freigegeben.', $preview); } @@ -104,7 +106,7 @@ public function test_withdrawing_the_release_removes_the_image_from_pages_and_cl $this->assertNotNull($medium->website_released_at); $this->refreshScoped(); - $this->get('/altbild')->assertSee('src="'.route('website.media', $medium).'"', false)->assertDontSee('/medien/cms/altbild', false); + $this->get('/altbild')->assertSee('src="'.app(WebsiteMedia::class)->present($medium)->url.'"', false)->assertDontSee('/medien/cms/altbild', false); $this->get('/medien/cms/altbild-abc123.jpg')->assertOk(); app(WebsiteRelease::class)->withdraw($medium); @@ -151,7 +153,7 @@ public function test_deleting_an_imported_medium_keeps_the_former_file_closed_an (new ImportCmsImages)->handle(app(WebsiteIntake::class)); $medium = WebsiteMediaAlias::query()->firstOrFail()->element; $this->refreshScoped(); - $this->get('/geloescht')->assertSee('src="'.route('website.media', $medium).'"', false); + $this->get('/geloescht')->assertSee('src="'.app(WebsiteMedia::class)->present($medium)->url.'"', false); $medium->delete(); $this->refreshScoped(); diff --git a/tests/Feature/FilmStillTest.php b/tests/Feature/FilmStillTest.php index 37e5444..e4bbaae 100644 --- a/tests/Feature/FilmStillTest.php +++ b/tests/Feature/FilmStillTest.php @@ -14,6 +14,7 @@ use App\Domain\Media\FilmStill; use App\Domain\Media\FilmStillSource; use App\Domain\Media\ThumbnailDeriver; +use App\Domain\Media\WebsiteMedia; use App\Domain\Media\WebsiteRelease; use App\Filament\Resources\Pages\Pages\EditPage; use App\Models\User; @@ -184,7 +185,7 @@ public function test_the_card_shows_the_stored_image_and_a_page_view_never_extra $html = $this->get('/filmkarte')->assertOk()->getContent(); } - $this->assertStringContainsString('src="'.route('website.media', $still).'"', $html); + $this->assertStringContainsString('src="'.app(WebsiteMedia::class)->present($still)->url.'"', $html); $this->assertStringContainsString('alt="Szene aus dem Film „Lara im Park“"', htmlspecialchars_decode($html)); $this->assertStringNotContainsString('lf-pc__panel--film', $html, 'Mit freigegebenem Bild erscheint keine Filmtafel.'); $this->assertStringNotContainsString('/redaktion/', $html); diff --git a/tests/Feature/LibraryProgramTest.php b/tests/Feature/LibraryProgramTest.php index c262f54..202189f 100644 --- a/tests/Feature/LibraryProgramTest.php +++ b/tests/Feature/LibraryProgramTest.php @@ -121,7 +121,7 @@ public function test_a_medium_preview_fills_the_program_until_the_program_has_it $this->actingAs($member) ->get(route('member.content', ['composition' => $released->composition->id, 'version' => $film->id])) ->assertOk() - ->assertSee('poster="'.$elementUrl.'"', false); + ->assertSee('poster="'.$elementUrl.'?g=mittel', false); $this->actingAs($member) ->get(route('member.library')) diff --git a/tests/Feature/ShopTilesTest.php b/tests/Feature/ShopTilesTest.php index cf35200..6af10e8 100644 --- a/tests/Feature/ShopTilesTest.php +++ b/tests/Feature/ShopTilesTest.php @@ -14,6 +14,7 @@ use App\Domain\Catalog\PresentationRole; use App\Domain\Commerce\ShopCatalog; use App\Domain\Commerce\ShopMarkers; +use App\Domain\Media\WebsiteMedia; use App\Filament\Pages\RedaktionelleStammdaten; use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle; use App\Models\User; @@ -135,10 +136,10 @@ public function test_a_released_cover_appears_on_the_tile_as_a_decorative_lazy_i $released = $this->image('Freigegebenes Titelbild', released: true); $this->cover($this->konflikte(), $released); - $this->assertSame(route('website.media', $released), $this->card()['image']['url']); + $this->assertSame(app(WebsiteMedia::class)->present($released)->url, $this->card()['image']['url']); $html = $this->get(route('shop'))->assertOk()->getContent(); - $this->assertStringContainsString('src="'.route('website.media', $released).'"', $html); - $this->assertMatchesRegularExpression('#id.'" alt="" loading="lazy"#', $html, 'Das Bild ist schmückend, der Titel ist der Link.'); + $this->assertStringContainsString('src="'.app(WebsiteMedia::class)->present($released)->url.'"', $html); + $this->assertMatchesRegularExpression('#id.'(\?v=\d+)?" alt="" loading="lazy"#', $html, 'Das Bild ist schmückend, der Titel ist der Link.'); } public function test_an_unreleased_first_cover_is_skipped_for_the_next_released_one(): void @@ -147,7 +148,7 @@ public function test_an_unreleased_first_cover_is_skipped_for_the_next_released_ $gallery = $this->image('Galeriebild freigegeben', released: true); $this->cover($this->konflikte(), $gallery, 'galerie', 2); - $this->assertSame(route('website.media', $gallery), $this->card()['image']['url']); + $this->assertSame(app(WebsiteMedia::class)->present($gallery)->url, $this->card()['image']['url']); } public function test_a_film_is_not_used_as_a_cover(): void