Gib Website-Bilder aus dem Medienmanager frei, ohne sie zu lizenzieren.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
72130d66c5
commit
13530b8171
18 files changed
+940
-2
No files matched your search
@@ -17,6 +17,10 @@ class ContentElement extends Model
|
||||
'description',
|
||||
'usage_note',
|
||||
'license_note',
|
||||
'website_credit',
|
||||
'website_alt',
|
||||
'website_released_at',
|
||||
'website_public_path',
|
||||
'summary',
|
||||
'thumbnail_path',
|
||||
'thumbnail_alt',
|
||||
@@ -30,6 +34,7 @@ protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'archived_at' => 'datetime',
|
||||
'website_released_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,18 @@ public function forElementUpload(ContentElement $element, string $incoming): voi
|
||||
$this->rememberElement($element, 'eigen');
|
||||
}
|
||||
|
||||
public function forWebsiteImage(ContentElement $element, string $incoming): void
|
||||
{
|
||||
if ($element->output_class !== 'bild' || ! $this->incomingIsSafe($incoming)) {
|
||||
$this->fail($element, 'Das Bild für die Website wurde nicht übernommen.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->still($element, Storage::disk('cms_incoming'), $incoming, 'element-'.$element->id);
|
||||
$this->rememberElement($element, 'eigen');
|
||||
}
|
||||
|
||||
public function forElementFrame(ContentElement $element, ContentElementVersion $version, float $seconds): void
|
||||
{
|
||||
if ($version->content_element_id !== $element->id || $element->output_class !== 'film') {
|
||||
@@ -201,6 +213,14 @@ private function readableDerived(mixed $path, string $prefix): bool
|
||||
return Storage::disk('media_derived')->exists($path);
|
||||
}
|
||||
|
||||
private function incomingIsSafe(string $incoming): bool
|
||||
{
|
||||
return (str_starts_with($incoming, 'cms/') || str_starts_with($incoming, 'vorschau/'))
|
||||
&& ! str_contains($incoming, '..')
|
||||
&& preg_match('#^(cms|vorschau)/[A-Za-z0-9._\-/]+$#', $incoming) === 1
|
||||
&& Storage::disk('cms_incoming')->exists($incoming);
|
||||
}
|
||||
|
||||
private function secondText(float $seconds): string
|
||||
{
|
||||
$seconds = max(0, min(7200, $seconds));
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
use App\Jobs\AcceptWebsiteImage;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Nimmt ein neues Website-Bild in den Medienmanager auf.
|
||||
* Die Warteschlange erzeugt danach die Ableitung und gibt sie frei.
|
||||
*/
|
||||
class WebsiteIntake
|
||||
{
|
||||
public function acceptImage(
|
||||
string $incomingPath,
|
||||
string $title,
|
||||
?string $credit = null,
|
||||
?string $alt = null,
|
||||
?User $actor = null,
|
||||
): ContentElement {
|
||||
$title = trim($title);
|
||||
|
||||
if ($title === '') {
|
||||
throw new DomainRuleException('Der Titel fehlt.');
|
||||
}
|
||||
|
||||
if (! $this->incomingIsReadable($incomingPath)) {
|
||||
throw new DomainRuleException('Die Bilddatei liegt nicht im Eingang.');
|
||||
}
|
||||
|
||||
$element = app(ContentService::class)->createElement('bild', 'bild', $title);
|
||||
app(IdentityProfile::class)->fill($element, [
|
||||
'display_title' => $title,
|
||||
'website_credit' => $credit,
|
||||
'website_alt' => $alt,
|
||||
], $actor);
|
||||
AcceptWebsiteImage::dispatch($element->id, $incomingPath, $actor?->id);
|
||||
|
||||
return $element->fresh();
|
||||
}
|
||||
|
||||
private function incomingIsReadable(string $path): bool
|
||||
{
|
||||
return (str_starts_with($path, 'cms/') || str_starts_with($path, 'vorschau/'))
|
||||
&& ! str_contains($path, '..')
|
||||
&& preg_match('#^(cms|vorschau)/[A-Za-z0-9._\-/]+$#', $path) === 1
|
||||
&& Storage::disk('cms_incoming')->exists($path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Lesesicht für Hero, Teaser und Slideshow.
|
||||
* Liefert nur eine freigegebene öffentliche Ableitung, sonst nichts.
|
||||
*/
|
||||
class WebsiteMedia
|
||||
{
|
||||
public function present(ContentElement|int $element): ?WebsitePresentation
|
||||
{
|
||||
$element = $element instanceof ContentElement
|
||||
? $element
|
||||
: ContentElement::query()->find($element);
|
||||
|
||||
if (! $element instanceof ContentElement || $element->website_released_at === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$path = $element->website_public_path;
|
||||
$expected = '#^website/'.$element->id.'/datei\.[a-z0-9]+$#';
|
||||
|
||||
if (! is_string($path) || preg_match($expected, $path) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! Storage::disk('media_public')->exists($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$title = trim((string) ($element->display_title ?: $element->working_title));
|
||||
$alt = trim((string) ($element->website_alt ?? ''));
|
||||
|
||||
return new WebsitePresentation(
|
||||
elementId: $element->id,
|
||||
title: $title,
|
||||
alt: $alt !== '' ? $alt : $title,
|
||||
credit: filled($element->website_credit) ? trim((string) $element->website_credit) : null,
|
||||
kind: $element->output_class === 'film' ? 'film' : 'bild',
|
||||
url: route('website.media', $element),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Slideshow: freigegebene Medien in der angegebenen Reihenfolge. Nicht freigegebene Einträge entfallen.
|
||||
*
|
||||
* @param list<int|string> $ids
|
||||
* @return list<WebsitePresentation>
|
||||
*/
|
||||
public function presentMany(array $ids): array
|
||||
{
|
||||
$presentations = [];
|
||||
|
||||
foreach ($ids as $id) {
|
||||
if (! is_numeric($id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$presentation = $this->present((int) $id);
|
||||
|
||||
if ($presentation !== null) {
|
||||
$presentations[] = $presentation;
|
||||
}
|
||||
}
|
||||
|
||||
return $presentations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
/**
|
||||
* Öffentliche Ableitung eines für die Website freigegebenen Mediums.
|
||||
* Enthält keine internen Vermerke und keine Adresse einer Bestandsdatei.
|
||||
*/
|
||||
final class WebsitePresentation
|
||||
{
|
||||
public function __construct(
|
||||
public readonly int $elementId,
|
||||
public readonly string $title,
|
||||
public readonly string $alt,
|
||||
public readonly ?string $credit,
|
||||
public readonly string $kind,
|
||||
public readonly string $url,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use App\Domain\Cms\Catalog\PublicMaterialReader;
|
||||
use App\Jobs\PublishWebsiteMedia;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Gibt eine Ableitung für die Website frei oder nimmt sie zurück.
|
||||
* Legt keinen Lizenzartikel an und ruft DecideAccess nicht auf.
|
||||
* Der Web-Prozess schreibt die öffentliche Datei nicht selbst; das tut die Warteschlange.
|
||||
*/
|
||||
class WebsiteRelease
|
||||
{
|
||||
public function release(ContentElement $element, ?User $actor = null): string
|
||||
{
|
||||
$refusal = $this->refusal($element);
|
||||
|
||||
if ($refusal !== null) {
|
||||
return $refusal;
|
||||
}
|
||||
|
||||
PublishWebsiteMedia::dispatch($element->id, 'release', $actor?->id);
|
||||
|
||||
return 'Für die Website freigegeben. Öffentliche Seiten lesen nur diese Ableitung.';
|
||||
}
|
||||
|
||||
public function withdraw(ContentElement $element, ?User $actor = null): string
|
||||
{
|
||||
PublishWebsiteMedia::dispatch($element->id, 'withdraw', $actor?->id);
|
||||
|
||||
return 'Die Website-Freigabe ist zurückgenommen.';
|
||||
}
|
||||
|
||||
public function refusal(ContentElement $element): ?string
|
||||
{
|
||||
if ($this->isConfidential($element)) {
|
||||
return 'Traineranleitungen werden nicht für die Website freigegeben.';
|
||||
}
|
||||
|
||||
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 null;
|
||||
}
|
||||
|
||||
public function derivedPath(ContentElement $element): ?string
|
||||
{
|
||||
if ($this->isConfidential($element)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($element->output_class === 'bild') {
|
||||
return $this->allowedDerivedPath($element->thumbnail_path, 'vorschau/');
|
||||
}
|
||||
|
||||
if ($element->output_class !== 'film') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$version = $element->versions()
|
||||
->where('status', ContentVersionStatus::Bereit->value)
|
||||
->orderByDesc('number')
|
||||
->first();
|
||||
|
||||
if ($version === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$path = MediaRendition::query()
|
||||
->where('content_element_version_id', $version->id)
|
||||
->where('role', 'preview')
|
||||
->orderByDesc('id')
|
||||
->value('path');
|
||||
|
||||
return $this->allowedDerivedPath($path, 'teaser/');
|
||||
}
|
||||
|
||||
public function publicPath(ContentElement $element, string $derivedPath): string
|
||||
{
|
||||
$extension = strtolower(pathinfo($derivedPath, PATHINFO_EXTENSION));
|
||||
|
||||
return 'website/'.$element->id.'/datei.'.$extension;
|
||||
}
|
||||
|
||||
private function isConfidential(ContentElement $element): bool
|
||||
{
|
||||
$slug = $element->editorialContentKind?->slug;
|
||||
|
||||
if ($slug === null && $element->editorial_content_kind_id !== null) {
|
||||
$slug = EditorialContentKind::query()->whereKey($element->editorial_content_kind_id)->value('slug');
|
||||
}
|
||||
|
||||
return in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true);
|
||||
}
|
||||
|
||||
private function allowedDerivedPath(mixed $path, string $prefix): ?string
|
||||
{
|
||||
if (! is_string($path) || ! str_starts_with($path, $prefix) || str_contains($path, '..')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||
|
||||
if (! in_array($extension, ['jpg', 'jpeg', 'png', 'webp', 'gif', 'mp4', 'webm'], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! Storage::disk('media_derived')->exists($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user