Files
LarsandCursor 13530b8171
Deploy Test / test (push) Successful in 48s
Deploy Test / deploy (push) Successful in 29s
Gib Website-Bilder aus dem Medienmanager frei, ohne sie zu lizenzieren.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 22:01:05 +01:00

55 lines
1.6 KiB
PHP

<?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);
}
}