Lasse Präsentationsmedien ohne Inhaltsfassung zu.
CI Feature / test (push) Successful in 53s
Deploy Test / test (push) Successful in 48s
Deploy Test / deploy (push) Successful in 22s

Bilder, Filme und Hörstücke lassen sich zuordnen und für die Website freigeben, ohne eine fachliche Fassung anzulegen. Unterrichtsfilme behalten die Teaserfassung an ihrer bereitgestellten Fassung.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-19 08:20:35 +01:00
1 parent 5590225f4f
commit 7b325f0d66
25 files changed
+734 -93

No files matched your search

+71
View File
@@ -0,0 +1,71 @@
<?php
namespace App\Domain\Media;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\DomainRuleException;
use Illuminate\Support\Facades\Storage;
/**
* Legt die technische Ableitung eines Präsentationsmediums an der Medienidentität ab.
* Es entsteht keine Inhaltsfassung, keine Freigabe und keine Berechtigung.
*/
class PresentationFile
{
public function store(ContentElement $element, string $incoming): void
{
if (! in_array($element->output_class, ['bild', 'film', 'audio'], true)) {
throw new DomainRuleException('Eine Präsentationsdatei ist ein Bild, ein Film oder ein Hörstück.');
}
if ($element->versions()->exists()) {
throw new DomainRuleException('Dieses Medium hat bereits eine Inhaltsfassung. Die Präsentationsdatei ersetzt sie nicht.');
}
if (! $this->readable($incoming)) {
throw new DomainRuleException('Die Datei liegt nicht im Eingang.');
}
$extension = strtolower(pathinfo($incoming, PATHINFO_EXTENSION));
$allowed = match ($element->output_class) {
'bild' => ['jpg', 'jpeg', 'png', 'webp', 'gif'],
'audio' => ['mp3', 'm4a', 'ogg'],
default => ['mp4', 'webm'],
};
if (! in_array($extension, $allowed, true)) {
throw new DomainRuleException('Diese Datei ist keine freigebbare Ableitung. Es wird keine Inhaltsfassung angelegt.');
}
$prefix = $element->output_class === 'bild' ? 'vorschau' : 'teaser';
$target = $prefix.'/'.$element->id.'/datei.'.$extension;
$stream = Storage::disk('cms_incoming')->readStream($incoming);
if (! is_resource($stream)) {
throw new DomainRuleException('Die Datei ließ sich nicht lesen.');
}
try {
Storage::disk('media_derived')->writeStream($target, $stream);
} finally {
fclose($stream);
}
if ($element->output_class === 'bild') {
$element->thumbnail_path = $target;
$element->thumbnail_source = 'eigen';
} else {
$element->preview_path = $target;
}
$element->save();
}
private function readable(string $path): bool
{
return (str_starts_with($path, 'inhalte/') || str_starts_with($path, 'cms/') || str_starts_with($path, 'vorschau/'))
&& ! str_contains($path, '..')
&& preg_match('#^(inhalte|cms|vorschau)/[A-Za-z0-9._\-/]+$#', $path) === 1
&& Storage::disk('cms_incoming')->exists($path);
}
}
+5 -1
View File
@@ -40,7 +40,11 @@ public function present(ContentElement|int $element): ?WebsitePresentation
title: $title,
alt: $alt !== '' ? $alt : $title,
credit: filled($element->website_credit) ? trim((string) $element->website_credit) : null,
kind: $element->output_class === 'film' ? 'film' : 'bild',
kind: match ($element->output_class) {
'film' => 'film',
'audio' => 'audio',
default => 'bild',
},
url: route('website.media', $element),
);
}
+19 -5
View File
@@ -44,7 +44,7 @@ public function refusal(ContentElement $element): ?string
}
if ($this->derivedPath($element) === null) {
return 'Für die Website fehlt eine freigebbare Ableitung. Beim Bild ist das das Vorschaubild, beim Film eine Teaserfassung unter teaser/. Die Originaldatei bleibt geschützt.';
return 'Für die Website fehlt eine freigebbare Ableitung. Beim Bild ist das das Vorschaubild. Film und Hörstück ohne Inhaltsfassung nutzen die Datei am Medium unter teaser/. Ein Film mit Inhaltsfassung nutzt die Teaserfassung seiner bereitgestellten Fassung. Die Originaldatei bleibt geschützt.';
}
return null;
@@ -57,7 +57,18 @@ public function derivedPath(ContentElement $element): ?string
}
if ($element->output_class === 'bild') {
return $this->allowedDerivedPath($element->thumbnail_path, 'vorschau/');
return $this->allowedDerivedPath($element->thumbnail_path, 'vorschau/', ['jpg', 'jpeg', 'png', 'webp', 'gif']);
}
if (in_array($element->output_class, ['film', 'audio'], true)) {
$extensions = $element->output_class === 'audio'
? ['mp3', 'm4a', 'ogg']
: ['mp4', 'webm'];
$own = $this->allowedDerivedPath($element->preview_path, 'teaser/', $extensions);
if ($own !== null) {
return $own;
}
}
if ($element->output_class !== 'film') {
@@ -79,7 +90,7 @@ public function derivedPath(ContentElement $element): ?string
->orderByDesc('id')
->value('path');
return $this->allowedDerivedPath($path, 'teaser/');
return $this->allowedDerivedPath($path, 'teaser/', ['mp4', 'webm']);
}
public function publicPath(ContentElement $element, string $derivedPath): string
@@ -100,7 +111,10 @@ private function isConfidential(ContentElement $element): bool
return in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true);
}
private function allowedDerivedPath(mixed $path, string $prefix): ?string
/**
* @param list<string> $extensions
*/
private function allowedDerivedPath(mixed $path, string $prefix, array $extensions): ?string
{
if (! is_string($path) || ! str_starts_with($path, $prefix) || str_contains($path, '..')) {
return null;
@@ -108,7 +122,7 @@ private function allowedDerivedPath(mixed $path, string $prefix): ?string
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if (! in_array($extension, ['jpg', 'jpeg', 'png', 'webp', 'gif', 'mp4', 'webm'], true)) {
if (! in_array($extension, $extensions, true)) {
return null;
}