Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
340c5f6b8d | ||
|
|
2ffabc2128 | ||
|
|
ae2e222077 | ||
|
|
f1e1f355b5 | ||
|
|
c6148589ff | ||
|
|
2eab8355f1 | ||
|
|
bf6eac2de9 | ||
|
|
8991efd19a | ||
|
|
46878552db | ||
|
|
903e8093a2 | ||
|
|
c442ff7bc9 | ||
|
|
c14cdfd0ec | ||
|
|
7145cf7b8d | ||
|
|
0e45dae0af | ||
|
|
f782c7d1a1 | ||
|
|
e9cb922d04 | ||
|
|
43a7778a33 | ||
|
|
f8a87827e9 | ||
|
|
4248ecffb8 | ||
|
|
759b3e1c02 | ||
|
|
57b2131632 |
No files matched your search
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Media\ImageVariants;
|
||||
use App\Jobs\DeriveImageVariants;
|
||||
use App\Jobs\DeriveWebsiteVariants;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Legt für vorhandene Bilder die kleineren Fassungen an (docs/architektur/bildvarianten.md). Neue Bilder bekommen sie beim
|
||||
* Ableiten; dieser Befehl holt den Bestand nach. Die Arbeit macht die Warteschlange (nur sie darf in derived/ und public/
|
||||
* schreiben); mit --now läuft sie hier im Prozess, den man dafür im Queue-Container startet.
|
||||
*/
|
||||
class DeriveMediaVariants extends Command
|
||||
{
|
||||
protected $signature = 'media:varianten {--now : Sofort hier ausführen statt in die Warteschlange zu legen} {--pretend : Nur zählen}';
|
||||
|
||||
protected $description = 'Legt für vorhandene Vorschaubilder und freigegebene Website-Bilder die kleineren Fassungen an';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$derived = Storage::disk('media_derived');
|
||||
$paths = [];
|
||||
|
||||
foreach ([ContentElement::query(), Composition::query()] as $query) {
|
||||
$query->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;
|
||||
}
|
||||
}
|
||||
@@ -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, 'klein', $element->updated_at)
|
||||
? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path)
|
||||
: 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, 'klein', $element->updated_at)
|
||||
? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path)
|
||||
: null,
|
||||
'kind' => $element?->editorialContentKind?->label,
|
||||
'output' => $element instanceof ContentElement ? (string) $element->output_class : '',
|
||||
|
||||
@@ -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, 'mittel', $element->updated_at);
|
||||
return app(EditorialCatalog::class)->cardUrl('element', $element->id, $element->thumbnail_path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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, 'mittel', $composition->updated_at) : null,
|
||||
previewImage: $includeNonPublic ? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path) : null,
|
||||
missing: $missing,
|
||||
texts: $texts,
|
||||
);
|
||||
|
||||
@@ -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, 'mittel', $shown->updated_at) : null;
|
||||
$previewImage = $includeNonPublic ? ThumbnailRef::url('editorial.card', 'element', (int) $element->id, $shown->thumbnail_path) : null;
|
||||
|
||||
return new CardSubject(
|
||||
title: $title,
|
||||
|
||||
@@ -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, 1920) : null;
|
||||
$imageUrl = $style['background'] === 'image' ? app(WebsiteImage::class)->url($style['image'], $context->preview) : null;
|
||||
$hasImage = $imageUrl !== null;
|
||||
|
||||
$classes = [
|
||||
|
||||
@@ -86,7 +86,7 @@ public function elementId(mixed $value): ?int
|
||||
return is_int($id) ? $id : null;
|
||||
}
|
||||
|
||||
public function presentation(mixed $value, ?ContentElement $loaded = null): ?WebsitePresentation
|
||||
public function presentation(mixed $value): ?WebsitePresentation
|
||||
{
|
||||
$id = $this->elementId($value);
|
||||
|
||||
@@ -95,8 +95,7 @@ public function presentation(mixed $value, ?ContentElement $loaded = null): ?Web
|
||||
}
|
||||
|
||||
if (! array_key_exists($id, $this->presentations)) {
|
||||
// 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;
|
||||
$this->presentations[$id] = $this->media->present($id) ?? false;
|
||||
}
|
||||
|
||||
return $this->presentations[$id] ?: null;
|
||||
@@ -106,12 +105,12 @@ public function presentation(mixed $value, ?ContentElement $loaded = null): ?Web
|
||||
* 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, ?int $width = null): ?string
|
||||
public function url(mixed $value, bool $preview = false): ?string
|
||||
{
|
||||
$presentation = $this->presentation($value);
|
||||
|
||||
if ($presentation !== null) {
|
||||
return $presentation->kind === 'bild' ? $presentation->urlForWidth($width) : null;
|
||||
return $presentation->kind === 'bild' ? $presentation->url : null;
|
||||
}
|
||||
|
||||
$id = $this->elementId($value);
|
||||
@@ -123,7 +122,7 @@ public function url(mixed $value, bool $preview = false, ?int $width = null): ?s
|
||||
|
||||
$element = ContentElement::query()->find($id);
|
||||
|
||||
return $element === null ? null : ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at);
|
||||
return $element === null ? null : ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
|
||||
}
|
||||
|
||||
$legacy = self::normalize($value);
|
||||
@@ -135,14 +134,6 @@ public function url(mixed $value, bool $preview = false, ?int $width = null): ?s
|
||||
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
|
||||
{
|
||||
@@ -178,7 +169,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, ?ContentElement $loaded = null): ?array
|
||||
public function status(mixed $value): ?array
|
||||
{
|
||||
$value = self::normalize($value);
|
||||
|
||||
@@ -203,16 +194,16 @@ public function status(mixed $value, ?ContentElement $loaded = null): ?array
|
||||
];
|
||||
}
|
||||
|
||||
$element = $loaded?->getKey() === $id ? $loaded : ContentElement::query()->with('editorialContentKind')->find($id);
|
||||
$element = 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, 'klein', $element->updated_at);
|
||||
$thumb = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
|
||||
$manageUrl = ContentElementResource::getUrl('view', ['record' => $element]);
|
||||
$public = $this->presentation($id, $element) !== null;
|
||||
$public = $this->presentation($id) !== null;
|
||||
|
||||
$note = match (true) {
|
||||
$public => 'Für die Website freigegeben.',
|
||||
@@ -301,7 +292,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, $element);
|
||||
$options[$element->id] = $this->optionHtml($element->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,9 +300,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, ?ContentElement $loaded = null): ?string
|
||||
public function optionHtml(mixed $value): ?string
|
||||
{
|
||||
$status = $this->status($value, $loaded);
|
||||
$status = $this->status($value);
|
||||
|
||||
if ($status === null) {
|
||||
return null;
|
||||
@@ -324,7 +315,7 @@ public function optionHtml(mixed $value, ?ContentElement $loaded = null): ?strin
|
||||
default => ['warn', 'Website: nicht freigegeben'],
|
||||
};
|
||||
$thumb = $status['thumb'] !== null
|
||||
? '<img src="'.e($status['thumb']).'" alt="" loading="lazy" decoding="async">'
|
||||
? '<img src="'.e($status['thumb']).'" alt="" loading="lazy">'
|
||||
: '<span class="luf-media-option-empty" aria-hidden="true"></span>';
|
||||
|
||||
return '<span class="luf-media-option">'.$thumb
|
||||
|
||||
@@ -302,7 +302,6 @@ 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) {
|
||||
|
||||
@@ -250,7 +250,6 @@ 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,
|
||||
|
||||
@@ -329,7 +329,6 @@ 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,
|
||||
|
||||
@@ -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, 'mittel', $film->updated_at) : null,
|
||||
'filmThumbnailUrl' => $film instanceof ContentElement ? ThumbnailRef::url('editorial.card', 'element', (int) $film->id, $film->thumbnail_path) : null,
|
||||
'filmStartSecond' => $film instanceof ContentElement ? ($stills->thumbnailSecond($film) ?? '0') : '0',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -349,7 +349,6 @@ 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),
|
||||
|
||||
@@ -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, 'mittel', $composition->updated_at)
|
||||
? ThumbnailRef::url('editorial.card', 'komposition', (int) $composition->id, $composition->thumbnail_path)
|
||||
: null,
|
||||
];
|
||||
}),
|
||||
|
||||
@@ -1,174 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
|
||||
/**
|
||||
* Größenstufen eines Bildes (docs/architektur/bildvarianten.md).
|
||||
*
|
||||
* Neben der Hauptdatei (`vorschau/element-12.jpg`, „voll“: bis 2400 px bei Bildern, 640 px sonst) liegen daneben
|
||||
* kleinere JPEG-Fassungen, benannt nach der Hauptdatei (`element-12-klein.jpg`). Es gibt keine Spalte dafür: Die Hauptdatei
|
||||
* bleibt `thumbnail_path`, die Fassungen folgen der Namensregel. Fehlt eine Fassung, gilt die Hauptdatei (kein Bruch bei
|
||||
* Bestand, der noch nicht abgeleitet ist).
|
||||
*
|
||||
* Verwaltungsoberfläche (Disk `media_derived`):
|
||||
* - `klein` 360 px: Auswahl, Listen, Karten (Anzeige bis etwa 180 px, doppelt für scharfe Bildschirme)
|
||||
* - `mittel` 960 px: Detailansicht, Vorschau, Titelbild im Editor
|
||||
* - voll: die Hauptdatei
|
||||
*
|
||||
* Website (Disk `media_public`, `website/{id}/datei-{breite}.jpg`): Breiten {@see self::PUBLIC_WIDTHS}, daneben die
|
||||
* Hauptdatei `datei.jpg`. Eine Fassung entsteht nur, wenn die Quelle breiter ist (nie vergrößern).
|
||||
*
|
||||
* Geschrieben wird nur in der Warteschlange; der Web-Prozess liest.
|
||||
*/
|
||||
class ImageVariants
|
||||
{
|
||||
/** @var array<string, int> */
|
||||
public const SIZES = ['klein' => 360, 'mittel' => 960];
|
||||
|
||||
/** @var list<int> */
|
||||
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<string> 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<string> 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<string, int> $targets Zielpfad → Breite
|
||||
* @return list<string>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,6 @@ 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 {
|
||||
@@ -98,7 +97,6 @@ public function place(ContentElement $element, string $incoming): void
|
||||
|
||||
$element->thumbnail_error = null;
|
||||
$element->save();
|
||||
$element->touch();
|
||||
Storage::disk('cms_incoming')->delete($incoming);
|
||||
}
|
||||
|
||||
|
||||
@@ -335,7 +335,6 @@ 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;
|
||||
@@ -345,7 +344,6 @@ 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
|
||||
@@ -390,7 +388,6 @@ 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)) {
|
||||
@@ -399,9 +396,6 @@ 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
|
||||
|
||||
@@ -2,37 +2,14 @@
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
|
||||
class ThumbnailRef
|
||||
{
|
||||
/**
|
||||
* 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
|
||||
public static function url(string $route, string $kind, int $id, mixed $path): ?string
|
||||
{
|
||||
if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$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);
|
||||
return route($route, ['kind' => $kind, 'subject' => $id]);
|
||||
}
|
||||
}
|
||||
@@ -45,37 +45,10 @@ public function present(ContentElement|int $element): ?WebsitePresentation
|
||||
'audio' => 'audio',
|
||||
default => 'bild',
|
||||
},
|
||||
// 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),
|
||||
url: route('website.media', $element),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* `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.
|
||||
*
|
||||
|
||||
@@ -15,19 +15,5 @@ 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;
|
||||
}
|
||||
}
|
||||
@@ -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, 'mittel', $element->updated_at);
|
||||
$url = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
|
||||
$caption = match ($element->thumbnail_source) {
|
||||
'eigen' => 'Eigenes Vorschaubild.',
|
||||
'datei' => 'Vorschaubild aus der Datei des Mediums.',
|
||||
|
||||
@@ -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, 'mittel', $element->updated_at),
|
||||
'pictureUrl' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
|
||||
'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, 'mittel', $element->updated_at),
|
||||
'image_url' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
|
||||
'error' => 'Vorschau der Kartenform. Ob jemand sie öffnen darf, entscheidet die Lizenz.',
|
||||
],
|
||||
]);
|
||||
|
||||
@@ -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, 'klein', $cover->updated_at) : null,
|
||||
'bild' => $cover !== null ? ThumbnailRef::url('editorial.card', 'element', $cover->id, $cover->thumbnail_path) : null,
|
||||
'symbol' => 'dokument',
|
||||
'url' => $url,
|
||||
'chips' => $chips,
|
||||
|
||||
@@ -18,14 +18,12 @@
|
||||
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;
|
||||
@@ -117,7 +115,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, 'klein', $element->updated_at),
|
||||
'image' => $this->cardUrl('element', $element->id, $element->thumbnail_path),
|
||||
'version_label' => match ($version->status) {
|
||||
ContentVersionStatus::Entwurf => 'Entwurf',
|
||||
ContentVersionStatus::Gesperrt => 'deaktiviert',
|
||||
@@ -165,7 +163,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, 'klein', $composition->updated_at),
|
||||
'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path),
|
||||
'version_label' => $version->status === ContentVersionStatus::Gesperrt
|
||||
? 'deaktiviert'
|
||||
: 'Fassung '.$version->number,
|
||||
@@ -200,7 +198,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, 'klein', $composition->updated_at),
|
||||
'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path),
|
||||
'version_label' => 'Entwurf',
|
||||
'identity' => 'zusammenstellung:'.$composition->id,
|
||||
'open_url' => route('editorial.draft-preview', ['composition' => $composition]),
|
||||
@@ -526,7 +524,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, 'klein', $element->updated_at)
|
||||
? $this->cardUrl('element', $element->id, $element->thumbnail_path)
|
||||
: null,
|
||||
'version_label' => 'Ohne Inhaltsfassung',
|
||||
'committed' => false,
|
||||
@@ -550,9 +548,13 @@ public function tone(string $outputClass, string $kindLabel): string
|
||||
};
|
||||
}
|
||||
|
||||
public function cardUrl(string $kind, int $id, ?string $path, ?string $size = null, CarbonInterface|int|string|null $version = null): ?string
|
||||
public function cardUrl(string $kind, int $id, ?string $path): ?string
|
||||
{
|
||||
return ThumbnailRef::url('editorial.card', $kind, $id, $path, $size, $version);
|
||||
if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return route('editorial.card', ['kind' => $kind, 'subject' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -889,7 +891,7 @@ public function filmPictures(array $members): array
|
||||
continue;
|
||||
}
|
||||
|
||||
$image = $this->cardUrl('element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at);
|
||||
$image = $this->cardUrl('element', $element->id, $element->thumbnail_path);
|
||||
|
||||
if ($image === null || isset($pictures[$element->id])) {
|
||||
continue;
|
||||
@@ -931,7 +933,7 @@ public function mediaPictures(string $query): array
|
||||
->limit(12)
|
||||
->get()
|
||||
->map(function (ContentElement $element): ?array {
|
||||
$image = $this->cardUrl('element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at);
|
||||
$image = $this->cardUrl('element', $element->id, $element->thumbnail_path);
|
||||
|
||||
if ($image === null) {
|
||||
return null;
|
||||
@@ -955,7 +957,7 @@ public function mediaPictures(string $query): array
|
||||
*/
|
||||
public function cover(Composition $composition, array $members): array
|
||||
{
|
||||
$own = $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path, 'mittel', $composition->updated_at);
|
||||
$own = $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path);
|
||||
|
||||
if ($own !== null) {
|
||||
return ['url' => $own, 'note' => null, 'own' => true];
|
||||
@@ -968,7 +970,7 @@ public function cover(Composition $composition, array $members): array
|
||||
}
|
||||
|
||||
return [
|
||||
'url' => $this->cardUrl($picture['kind'], $picture['subject'], 'vorschau/gesetzt', 'mittel'),
|
||||
'url' => $this->cardUrl($picture['kind'], $picture['subject'], 'vorschau/gesetzt'),
|
||||
'note' => $picture['note'],
|
||||
'own' => false,
|
||||
];
|
||||
|
||||
@@ -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, 'klein', $element->updated_at),
|
||||
'image' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
|
||||
'imageAlt' => trim((string) ($element->thumbnail_alt ?: $element->working_title)),
|
||||
'imageNote' => $this->imageNote($element),
|
||||
'presentation' => $this->isPresentationMedium($element, $portrait['versionCount']),
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Concerns;
|
||||
|
||||
use App\Domain\Media\ImageVariants;
|
||||
use App\Jobs\DeriveImageVariants;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Liefert ein Bild einer Disk mit Zwischenspeicherung aus (docs/architektur/bildvarianten.md).
|
||||
*
|
||||
* Mit Versionsangabe in der Adresse (`?v=`) ändert sich die Adresse, sobald sich das Bild ändert; der Browser darf es
|
||||
* dann ein Jahr behalten. Ohne Version bleibt es bei einer Rückfrage mit ETag und Last-Modified (304 ohne Inhalt).
|
||||
*/
|
||||
trait ServesImages
|
||||
{
|
||||
/**
|
||||
* @param 'public'|'private' $scope `private` für alles, was eine Anmeldung oder Berechtigung voraussetzt
|
||||
*/
|
||||
protected function respondWithImage(Request $request, string $diskName, string $path, string $scope = 'private', bool $versioned = false): Response
|
||||
{
|
||||
$disk = Storage::disk($diskName);
|
||||
$headers = [
|
||||
'Content-Disposition' => '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');
|
||||
$resolved = ImageVariants::resolve(Storage::disk($diskName), $path, is_string($size) ? $size : null);
|
||||
|
||||
// Bestand ohne Fassungen: Die Hauptdatei geht hinaus, und die Warteschlange legt die Fassungen an (der Web-Prozess
|
||||
// schreibt nie). Höchstens einmal je Tag und Bild; ist die Quelle schmaler als die Stufe, bleibt es bei der Hauptdatei.
|
||||
if ($resolved === $path && ImageVariants::isSize($size) && Cache::add('bildvarianten.'.md5($path), true, now()->addDay())) {
|
||||
DeriveImageVariants::dispatch($path);
|
||||
}
|
||||
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
/** `?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;
|
||||
}
|
||||
}
|
||||
@@ -12,18 +12,15 @@
|
||||
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\Response as SymfonyResponse;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class EditorialPreviewController extends Controller
|
||||
{
|
||||
use ServesImages;
|
||||
|
||||
public function show(Composition $composition, ?CompositionVersion $version = null): View
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
@@ -107,7 +104,7 @@ public function draft(Composition $composition): View
|
||||
);
|
||||
}
|
||||
|
||||
public function card(Request $request, string $kind, int $subject): SymfonyResponse
|
||||
public function card(string $kind, int $subject): StreamedResponse
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
abort_unless(in_array($kind, ['element', 'komposition'], true), 404);
|
||||
@@ -119,13 +116,7 @@ public function card(Request $request, string $kind, int $subject): SymfonyRespo
|
||||
$disk = Storage::disk('media_derived');
|
||||
abort_unless($disk->exists($path), 404);
|
||||
|
||||
return $this->respondWithImage(
|
||||
$request,
|
||||
'media_derived',
|
||||
$this->imagePathFor($request, 'media_derived', $path),
|
||||
'private',
|
||||
$this->hasImageVersion($request),
|
||||
);
|
||||
return $disk->response($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
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;
|
||||
@@ -33,13 +32,10 @@
|
||||
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',
|
||||
@@ -365,7 +361,7 @@ public function rendition(
|
||||
return $disk->response($datei, basename($datei), ['Content-Disposition' => 'inline']);
|
||||
}
|
||||
|
||||
public function thumbnail(Request $request, string $kind, int $subject): SymfonyResponse
|
||||
public function thumbnail(Request $request, string $kind, int $subject): StreamedResponse
|
||||
{
|
||||
abort_unless(in_array($kind, ['komposition', 'element'], true), 404);
|
||||
$model = $kind === 'komposition'
|
||||
@@ -377,13 +373,7 @@ public function thumbnail(Request $request, string $kind, int $subject): Symfony
|
||||
$disk = Storage::disk('media_derived');
|
||||
abort_unless($disk->exists($path), 404);
|
||||
|
||||
return $this->respondWithImage(
|
||||
$request,
|
||||
'media_derived',
|
||||
$this->imagePathFor($request, 'media_derived', $path),
|
||||
'private',
|
||||
$this->hasImageVersion($request),
|
||||
);
|
||||
return $disk->response($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,22 +3,16 @@
|
||||
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 Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class WebsiteMediaController extends Controller
|
||||
{
|
||||
use ServesByteRanges;
|
||||
use ServesImages;
|
||||
|
||||
public function show(Request $request, ContentElement $element, WebsiteMedia $media): Response
|
||||
public function show(Request $request, ContentElement $element, WebsiteMedia $media): StreamedResponse
|
||||
{
|
||||
$presentation = $media->present($element);
|
||||
abort_if($presentation === null, 404);
|
||||
@@ -26,45 +20,6 @@ public function show(Request $request, ContentElement $element, WebsiteMedia $me
|
||||
$path = $element->website_public_path;
|
||||
abort_if(! is_string($path), 404);
|
||||
|
||||
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;
|
||||
return $this->respondWithRanges($request, 'media_public', $path, $presentation->kind !== 'bild');
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,6 @@ 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),
|
||||
];
|
||||
@@ -114,7 +113,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, 'mittel', $element->updated_at);
|
||||
$imageUrl = $element === null ? null : ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path);
|
||||
$media[$key] = ($media[$key] ?? []) + [
|
||||
'used_in' => [],
|
||||
'versions' => [],
|
||||
@@ -377,7 +376,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, 'mittel', $element->updated_at);
|
||||
$poster = ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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, 'klein', $composition->updated_at)
|
||||
: ($element === null ? null : ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at));
|
||||
? ThumbnailRef::url('member.thumbnail', 'komposition', $composition->id, $composition->thumbnail_path)
|
||||
: ($element === null ? null : ThumbnailRef::url('member.thumbnail', 'element', $element->id, $element->thumbnail_path));
|
||||
}
|
||||
|
||||
$title = $composition !== null
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Domain\Media\ImageVariants;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Legt die kleineren Fassungen (klein, mittel) zu einem vorhandenen Vorschaubild an. Läuft nur in der Warteschlange, die in
|
||||
* derived/ schreiben darf. Auslöser: Bestand ohne Fassungen, den die Auslieferung oder der Befehl `media:varianten` findet.
|
||||
*/
|
||||
class DeriveImageVariants implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(public readonly string $path) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if (preg_match('#^vorschau/[A-Za-z0-9._\-/]+$#', $this->path) !== 1 || str_contains($this->path, '..')) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImageVariants::generate(Storage::disk('media_derived'), $this->path);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Media\ImageVariants;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Legt die Breiten für die Website zu einem bereits freigegebenen Bild an (Bestand von vor den Bildfassungen). Verändert
|
||||
* weder die Freigabe noch den Prüfverlauf; die Freigabe selbst schreibt die Fassungen in {@see PublishWebsiteMedia}.
|
||||
*/
|
||||
class DeriveWebsiteVariants implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(public readonly int $elementId) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$element = ContentElement::query()->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);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
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;
|
||||
@@ -52,12 +51,6 @@ 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());
|
||||
@@ -76,8 +69,6 @@ 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
|
||||
|
||||
@@ -943,20 +943,3 @@ ## 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 einen Auftrag an (Website: `DeriveWebsiteVariants`, höchstens einmal je Stunde und Bild; Verwaltung und Mitgliederbereich: `DeriveImageVariants`, höchstens einmal je Tag und Bild); `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.
|
||||
@@ -1,42 +0,0 @@
|
||||
# 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.
|
||||
@@ -17,7 +17,7 @@
|
||||
<{{ $as }} {{ $attributes->class('vw-eintrag') }}>
|
||||
<span class="vw-bild">
|
||||
@if (filled($bild))
|
||||
<img src="{{ $bild }}" alt="{{ $bildAlt }}" loading="lazy" decoding="async">
|
||||
<img src="{{ $bild }}" alt="{{ $bildAlt }}" loading="lazy">
|
||||
@else
|
||||
<span class="vw-bild-ersatz" data-symbol="{{ $symbol }}">@include('filament.verwaltung.icon', ['name' => $symbol])@if (filled($bildFehlt))<span class="vw-sr">{{ $bildFehlt }}</span>@endif</span>
|
||||
@endif
|
||||
|
||||
@@ -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, 'mittel', $version->element->updated_at);
|
||||
$poster = \App\Domain\Media\ThumbnailRef::url('editorial.card', 'element', $version->element->id, $version->element->thumbnail_path);
|
||||
$playback = $class === 'film' ? app(\App\Http\Controllers\ContentPreviewController::class)->playback($version) : null;
|
||||
@endphp
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
x-on:keydown.alt.arrow-down.prevent="$wire.movePart({{ $index }}, 1)">
|
||||
<span class="vw-bild is-klein">
|
||||
@if (! empty($member['image']))
|
||||
<img src="{{ $member['image'] }}" alt="" loading="lazy" decoding="async">
|
||||
<img src="{{ $member['image'] }}" alt="" loading="lazy">
|
||||
@else
|
||||
<span class="vw-bild-ersatz">@include('filament.verwaltung.icon', ['name' => $symbol($member['tone'] ?? null)])</span>
|
||||
@endif
|
||||
@@ -70,7 +70,7 @@
|
||||
@forelse ($kinder as $kind)
|
||||
<div class="vw-quellenzeile">
|
||||
<span class="vw-bild is-mini">
|
||||
@if (! empty($kind['image']))<img src="{{ $kind['image'] }}" alt="" loading="lazy" decoding="async">@else<span class="vw-bild-ersatz">@include('filament.verwaltung.icon', ['name' => $symbol($kind['tone'])])</span>@endif
|
||||
@if (! empty($kind['image']))<img src="{{ $kind['image'] }}" alt="" loading="lazy">@else<span class="vw-bild-ersatz">@include('filament.verwaltung.icon', ['name' => $symbol($kind['tone'])])</span>@endif
|
||||
</span>
|
||||
<span><strong>{{ $kind['title'] }}</strong><br><span class="vw-feld-hilfe">{{ $kind['kind'] }}@if ($kind['role'] !== '') · {{ $kind['role'] }}@endif</span></span>
|
||||
</div>
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
@endunless
|
||||
<span class="vw-bild">
|
||||
@if (! empty($row['image']))
|
||||
<img src="{{ $row['image'] }}" alt="" loading="lazy" decoding="async">
|
||||
<img src="{{ $row['image'] }}" alt="" loading="lazy">
|
||||
@else
|
||||
<span class="vw-bild-ersatz">@include('filament.verwaltung.icon', ['name' => $symbol($row['output'])])</span>
|
||||
@endif
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<div class="mb-player player">
|
||||
@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, 'mittel', $entry['version']->element->updated_at),
|
||||
'poster' => \App\Domain\Media\ThumbnailRef::url('member.thumbnail', 'element', $entry['version']->element->id, $entry['version']->element->thumbnail_path),
|
||||
])
|
||||
</div>
|
||||
<div class="mb-actions">
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<header class="mb-detail-head">
|
||||
<div class="mb-detail-visual">
|
||||
@if ($picture)
|
||||
<img src="{{ route('member.thumbnail', ['kind' => $picture['kind'], 'subject' => $picture['subject'], 'g' => 'mittel']) }}" alt="{{ $picture['alt'] ?: '' }}">
|
||||
<img src="{{ route('member.thumbnail', ['kind' => $picture['kind'], 'subject' => $picture['subject']]) }}" alt="{{ $picture['alt'] ?: '' }}">
|
||||
@else
|
||||
<span class="mb-card-placeholder" aria-hidden="true"><x-dynamic-component :component="'heroicon-o-'.($is_module ? 'rectangle-stack' : 'squares-2x2')" /></span>
|
||||
@endif
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
])>
|
||||
@if ($item['imageUrl'])
|
||||
<div class="card-media">
|
||||
<img class="card-image" src="{{ $item['imageUrl'] }}" @if (! empty($item['imageSrcset'])) srcset="{{ $item['imageSrcset'] }}" sizes="(min-width: 900px) 40vw, 100vw" @endif alt="" loading="lazy" decoding="async">
|
||||
<img class="card-image" src="{{ $item['imageUrl'] }}" alt="" loading="lazy" decoding="async">
|
||||
</div>
|
||||
@endif
|
||||
<div class="card-body">
|
||||
|
||||
@@ -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)
|
||||
<img class="lf-hero__photo" src="{{ $imageUrl }}" @if (! empty($imageSrcset)) srcset="{{ $imageSrcset }}" sizes="100vw"@endif alt="{{ $imageAlt ?? '' }}" {!! $loading !!} decoding="async">
|
||||
<img class="lf-hero__photo" src="{{ $imageUrl }}" alt="{{ $imageAlt ?? '' }}" {!! $loading !!} decoding="async">
|
||||
@endif
|
||||
@if ($videoUrl !== null)
|
||||
<video class="lf-hero__video" muted loop playsinline preload="none" disablepictureinpicture disableremoteplayback tabindex="-1" aria-hidden="true"></video>
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
@endif
|
||||
@if ($imageUrl)
|
||||
<div class="lf-bt__media" @if ($clipUrl !== null) data-card-clip data-clip-src="{{ $clipUrl }}" data-clip-title="{{ $clipTitle }}" @endif>
|
||||
<img class="lf-bt__image" src="{{ $imageUrl }}" @if (! empty($imageSrcset)) srcset="{{ $imageSrcset }}" sizes="100vw" @endif alt="{{ $imageAlt ?? '' }}" @if (! empty($first)) loading="eager" fetchpriority="high" @else loading="lazy" @endif decoding="async">
|
||||
<img class="lf-bt__image" src="{{ $imageUrl }}" alt="{{ $imageAlt ?? '' }}" @if (! empty($first)) loading="eager" fetchpriority="high" @else loading="lazy" @endif decoding="async">
|
||||
@include('widgets.partials.card-clip')
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
]) style="--pc-focus-x: {{ $focus['x'] }}%; --pc-focus-y: {{ $focus['y'] }}%">
|
||||
@if ($imageUrl !== null || $libraryImage !== null)
|
||||
<div class="lf-pc__visual" @if ($clipUrl !== null) data-card-clip data-clip-src="{{ $clipUrl }}" data-clip-title="{{ $clipTitle }}" @endif>
|
||||
<img class="lf-pc__image" src="{{ $imageUrl ?? $libraryImage }}" @if ($imageUrl !== null && ! empty($imageSrcset)) srcset="{{ $imageSrcset }}" sizes="(min-width: 900px) 50vw, 100vw" @endif alt="{{ $imageUrl !== null ? $alt : '' }}" loading="lazy" decoding="async">
|
||||
<img class="lf-pc__image" src="{{ $imageUrl ?? $libraryImage }}" alt="{{ $imageUrl !== null ? $alt : '' }}" loading="lazy" decoding="async">
|
||||
@include('widgets.partials.card-clip')
|
||||
@if ($show['kind'] && $subject->badge !== null && empty($bare))
|
||||
<span class="lf-pc__badge">{{ $subject->badge }}</span>
|
||||
|
||||
+1
-19
@@ -28,13 +28,7 @@
|
||||
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');
|
||||
@@ -44,19 +38,7 @@
|
||||
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');
|
||||
// Ö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');
|
||||
Route::get('/website-medien/{element}', [WebsiteMediaController::class, 'show'])->whereNumber('element')->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).
|
||||
|
||||
@@ -1,353 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
||||
use App\Domain\Media\ImageVariants;
|
||||
use App\Domain\Media\ThumbnailDeriver;
|
||||
use App\Domain\Media\WebsiteIntake;
|
||||
use App\Domain\Media\WebsiteMedia;
|
||||
use App\Domain\Media\WebsiteRelease;
|
||||
use App\Filament\Support\MediaLibrary;
|
||||
use App\Jobs\DeriveImageVariants;
|
||||
use App\Jobs\DeriveWebsiteVariants;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Bildfassungen (docs/architektur/bildvarianten.md): klein, mittel und voll für die Verwaltung, Breiten für die Website,
|
||||
* Auslieferung mit Zwischenspeicherung und Ausweichen auf die volle Datei.
|
||||
*/
|
||||
class BildvariantenTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Storage::fake('cms_incoming');
|
||||
Storage::fake('media_derived');
|
||||
Storage::fake('media_public');
|
||||
Storage::fake('media_originals');
|
||||
Cache::flush();
|
||||
}
|
||||
|
||||
public function test_variants_are_written_next_to_the_main_file_and_never_enlarged(): void
|
||||
{
|
||||
$disk = Storage::disk('media_derived');
|
||||
$disk->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_a_missing_variant_is_derived_by_the_queue_once_per_day(): void
|
||||
{
|
||||
[$element, $disk] = $this->elementWithThumbnail(2000, 1000);
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
Queue::fake();
|
||||
|
||||
$url = route('editorial.card', ['kind' => 'element', 'subject' => $element->id, 'g' => 'klein']);
|
||||
$this->actingAs($editor, 'staff')->get($url)->assertOk();
|
||||
$this->actingAs($editor, 'staff')->get($url)->assertOk();
|
||||
$this->actingAs($editor, 'staff')->get(route('editorial.card', ['kind' => 'element', 'subject' => $element->id]))->assertOk();
|
||||
|
||||
Queue::assertPushed(DeriveImageVariants::class, 1);
|
||||
$disk->assertMissing('vorschau/element-'.$element->id.'-klein.jpg');
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -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('<img class="lf-pc__image" src="'.app(WebsiteMedia::class)->present($image->id)->url.'"', $card);
|
||||
$this->assertStringContainsString('<img class="lf-pc__image" src="'.route('website.media', $image).'"', $card);
|
||||
$this->assertStringContainsString('data-clip-src="'.route('website.media', $trailer).'"', $card);
|
||||
$this->assertStringNotContainsString('lf-pc__visual--panel', $card);
|
||||
}
|
||||
|
||||
@@ -88,9 +88,7 @@ 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('<img class="lf-bt__image" src="'.app(WebsiteMedia::class)->present($image->id)->url.'"', $html);
|
||||
$this->assertStringContainsString('alt="Gruppe im Park"', $html);
|
||||
$this->assertStringContainsString('srcset="', $html);
|
||||
$this->assertStringContainsString('<img class="lf-bt__image" src="'.route('website.media', $image).'" alt="Gruppe im Park"', $html);
|
||||
|
||||
$normalized = app(WidgetRegistry::class)->normalize($this->widget([], ['image' => $image->id])[0]['slots']);
|
||||
$this->assertSame($image->id, $normalized[0]['refs']['image']);
|
||||
|
||||
@@ -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, 'g' => 'mittel']).'&v=', $preview);
|
||||
$this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'element', 'subject' => $film->id]).'"', $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('<li>Dauer 25 Min.</li>', $preview);
|
||||
$this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'komposition', 'subject' => $program->composition_id, 'g' => 'mittel']).'&v=', $preview);
|
||||
$this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'komposition', 'subject' => $program->composition_id]).'"', $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.');
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
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;
|
||||
@@ -48,7 +47,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 = app(WebsiteMedia::class)->present($medium)->url;
|
||||
$url = route('website.media', $medium);
|
||||
|
||||
$revision = $this->publish('/medien-ueberall', [
|
||||
['layout' => 'u4', 'style' => ['background' => 'image', 'image' => $medium->id, 'overlay' => 'light'], 'slots' => [
|
||||
@@ -64,8 +63,7 @@ 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(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->assertSame(4, substr_count($main, 'src="'.$url.'"'), 'Hintergrund, Einstieg, Bild und Text, Karte verwenden dasselbe Medium.');
|
||||
$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);
|
||||
@@ -89,7 +87,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, 'g' => 'mittel']).'&v=', $preview);
|
||||
$this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'element', 'subject' => $medium->id]).'"', $preview);
|
||||
$this->assertStringContainsString('Das gewählte Bild „Noch nicht freigegeben“ erscheint öffentlich nicht: Nicht für die Website freigegeben.', $preview);
|
||||
}
|
||||
|
||||
@@ -106,7 +104,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="'.app(WebsiteMedia::class)->present($medium)->url.'"', false)->assertDontSee('/medien/cms/altbild', false);
|
||||
$this->get('/altbild')->assertSee('src="'.route('website.media', $medium).'"', false)->assertDontSee('/medien/cms/altbild', false);
|
||||
$this->get('/medien/cms/altbild-abc123.jpg')->assertOk();
|
||||
|
||||
app(WebsiteRelease::class)->withdraw($medium);
|
||||
@@ -153,7 +151,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="'.app(WebsiteMedia::class)->present($medium)->url.'"', false);
|
||||
$this->get('/geloescht')->assertSee('src="'.route('website.media', $medium).'"', false);
|
||||
|
||||
$medium->delete();
|
||||
$this->refreshScoped();
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
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;
|
||||
@@ -185,7 +184,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="'.app(WebsiteMedia::class)->present($still)->url.'"', $html);
|
||||
$this->assertStringContainsString('src="'.route('website.media', $still).'"', $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);
|
||||
|
||||
@@ -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.'?g=mittel', false);
|
||||
->assertSee('poster="'.$elementUrl.'"', false);
|
||||
|
||||
$this->actingAs($member)
|
||||
->get(route('member.library'))
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
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;
|
||||
@@ -136,10 +135,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(app(WebsiteMedia::class)->present($released)->url, $this->card()['image']['url']);
|
||||
$this->assertSame(route('website.media', $released), $this->card()['image']['url']);
|
||||
$html = $this->get(route('shop'))->assertOk()->getContent();
|
||||
$this->assertStringContainsString('src="'.app(WebsiteMedia::class)->present($released)->url.'"', $html);
|
||||
$this->assertMatchesRegularExpression('#<img src="[^"]+website-medien/'.$released->id.'(\?v=\d+)?" alt="" loading="lazy"#', $html, 'Das Bild ist schmückend, der Titel ist der Link.');
|
||||
$this->assertStringContainsString('src="'.route('website.media', $released).'"', $html);
|
||||
$this->assertMatchesRegularExpression('#<img src="[^"]+website-medien/'.$released->id.'" 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
|
||||
@@ -148,7 +147,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(app(WebsiteMedia::class)->present($gallery)->url, $this->card()['image']['url']);
|
||||
$this->assertSame(route('website.media', $gallery), $this->card()['image']['url']);
|
||||
}
|
||||
|
||||
public function test_a_film_is_not_used_as_a_cover(): void
|
||||
|
||||
Reference in new issue
Block a user