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
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user