Wähle das Vorschaubild am Medium und nutze es als Standard in der Anzeige und in Modulen.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
f86032cb5f
commit
8e77defaca
18 files changed
+664
-26
No files matched your search
@@ -20,6 +20,7 @@ class ContentElement extends Model
|
||||
'summary',
|
||||
'thumbnail_path',
|
||||
'thumbnail_alt',
|
||||
'thumbnail_source',
|
||||
'thumbnail_error',
|
||||
'editorial_content_kind_id',
|
||||
'archived_at',
|
||||
|
||||
@@ -24,12 +24,48 @@ public function forElement(ContentElement $element): void
|
||||
}
|
||||
|
||||
if (in_array($element->output_class, ['film', 'audio'], true)) {
|
||||
$this->frame($element, $file);
|
||||
$this->frame($element, $version, $file);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->still($element, Storage::disk('media_derived'), $file, 'element-'.$element->id);
|
||||
$this->rememberElement($element, 'datei');
|
||||
}
|
||||
|
||||
public function forElementUpload(ContentElement $element, string $incoming): void
|
||||
{
|
||||
if (! str_starts_with($incoming, 'vorschau/') || str_contains($incoming, '..')) {
|
||||
$this->fail($element, 'Das Vorschaubild 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') {
|
||||
$this->fail($element, 'Aus dieser Filmstelle ließ sich kein Vorschaubild erzeugen.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$bytes = $this->jpegAtVersion($version, $seconds);
|
||||
|
||||
if (! is_string($bytes)) {
|
||||
$this->fail($element, 'Aus dieser Filmstelle ließ sich kein Vorschaubild erzeugen.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$name = 'element-'.$element->id;
|
||||
$path = 'vorschau/'.$name.'.jpg';
|
||||
Storage::disk('media_derived')->put($path, $bytes);
|
||||
$this->still($element, Storage::disk('media_derived'), $path, $name);
|
||||
$this->rememberElement($element, 'frame:'.$version->id.'@'.$this->secondText($seconds));
|
||||
}
|
||||
|
||||
public function forCompositionUpload(Composition $composition, string $incoming): void
|
||||
@@ -166,7 +202,7 @@ private function secondText(float $seconds): string
|
||||
return rtrim(rtrim($text, '0'), '.') ?: '0';
|
||||
}
|
||||
|
||||
private function frame(ContentElement $element, string $file): void
|
||||
private function frame(ContentElement $element, ContentElementVersion $version, string $file): void
|
||||
{
|
||||
$binary = (new ExecutableFinder)->find('ffmpeg');
|
||||
$disk = Storage::disk('media_derived');
|
||||
@@ -200,8 +236,13 @@ private function frame(ContentElement $element, string $file): void
|
||||
}
|
||||
|
||||
$element->thumbnail_path = $target;
|
||||
$element->thumbnail_alt = $element->working_title;
|
||||
if (! filled($element->thumbnail_alt)) {
|
||||
$element->thumbnail_alt = $element->working_title;
|
||||
}
|
||||
$element->thumbnail_error = null;
|
||||
if ($element->output_class === 'film') {
|
||||
$element->thumbnail_source = 'frame:'.$version->id.'@0';
|
||||
}
|
||||
$element->save();
|
||||
}
|
||||
|
||||
@@ -243,7 +284,7 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st
|
||||
Storage::disk('media_derived')->put($path, $bytes);
|
||||
$subject->thumbnail_path = $path;
|
||||
|
||||
if (! ($subject instanceof Composition && filled($subject->thumbnail_alt))) {
|
||||
if (! filled($subject->thumbnail_alt)) {
|
||||
$subject->thumbnail_alt = $subject instanceof Composition ? $subject->designation : $subject->working_title;
|
||||
}
|
||||
|
||||
@@ -251,6 +292,18 @@ private function still(ContentElement|Composition $subject, Filesystem $disk, st
|
||||
$subject->save();
|
||||
}
|
||||
|
||||
private function rememberElement(ContentElement $element, string $source): void
|
||||
{
|
||||
$element->refresh();
|
||||
|
||||
if ($element->thumbnail_error !== null || ! filled($element->thumbnail_path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$element->thumbnail_source = $source;
|
||||
$element->save();
|
||||
}
|
||||
|
||||
private function rememberChoice(Composition $composition, string $source): void
|
||||
{
|
||||
$composition->refresh();
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
class ThumbnailRef
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
return route($route, ['kind' => $kind, 'subject' => $id]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user