Wähle das Vorschaubild auch aus der Website-Datei eines Films ohne Fassung
Die Filmstelle konnte nur aus der Datei einer Inhaltsfassung gezogen werden; ein Medium mit reiner Website-Datei hatte keine Quelle. Jetzt zieht die Auswahl die Stelle aus der Website-Datei (Herkunft frame:0@Sekunde, bestehende Leser bleiben gültig). Die Vorschau des Einzelbilds liegt hinter einer Redaktions-Route. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
be932c113a
commit
5e28538551
7 files changed
+142
-6
No files matched your search
@@ -87,6 +87,27 @@ public function forElementFrame(ContentElement $element, ContentElementVersion $
|
||||
$this->rememberElement($element, 'frame:'.$version->id.'@'.$this->secondText($seconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Vorschaubild aus einer Stelle der Website-Datei. Die Herkunft steht als `frame:0@{Sekunde}`; die 0 steht für die
|
||||
* Website-Datei (es gibt keine Fassung), alle Leser der Herkunft kommen damit zurecht.
|
||||
*/
|
||||
public function forElementWebsiteFrame(ContentElement $element, float $seconds): void
|
||||
{
|
||||
$bytes = $this->jpegAtWebsiteFile($element, $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:0@'.$this->secondText($seconds));
|
||||
}
|
||||
|
||||
public function forCompositionUpload(Composition $composition, string $incoming): void
|
||||
{
|
||||
if (! str_starts_with($incoming, 'vorschau/') || str_contains($incoming, '..')) {
|
||||
@@ -187,7 +208,26 @@ public function frameJpeg(ContentElementVersion $version, float $seconds, int $w
|
||||
|
||||
$file = $this->frameInput($version, $original);
|
||||
|
||||
if ($file === null) {
|
||||
return $file === null ? null : $this->jpegFromFile($file, $seconds, $width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Einzelbild aus der Website-Datei eines Films (`teaser/`), für Medien ohne Inhaltsfassung.
|
||||
*/
|
||||
public function jpegAtWebsiteFile(ContentElement $element, float $seconds): ?string
|
||||
{
|
||||
$file = $element->preview_path;
|
||||
|
||||
if ($element->output_class !== 'film' || ! $this->readableDerived($file, 'teaser/')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->jpegFromFile($file, $seconds, 640);
|
||||
}
|
||||
|
||||
private function jpegFromFile(string $file, float $seconds, int $width): ?string
|
||||
{
|
||||
if ($seconds < 0 || $seconds > 7200) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -266,8 +266,9 @@ public function adoptFrame(): void
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
$shown = $this->shownVersion();
|
||||
$fromWebsiteFile = ! $shown instanceof ContentElementVersion && $this->hasWebsiteFilm($element);
|
||||
|
||||
if (! $shown instanceof ContentElementVersion || $element->output_class !== 'film') {
|
||||
if ((! $shown instanceof ContentElementVersion && ! $fromWebsiteFile) || $element->output_class !== 'film') {
|
||||
$this->pictureFeedback = 'Für dieses Medium gibt es keine Filmstelle.';
|
||||
|
||||
return;
|
||||
@@ -290,7 +291,9 @@ public function adoptFrame(): void
|
||||
$this->keepAlt($element);
|
||||
$element->thumbnail_error = null;
|
||||
$element->save();
|
||||
DeriveThumbnail::dispatch('element', $element->id, null, null, $shown->id, $seconds);
|
||||
$fromWebsiteFile
|
||||
? DeriveThumbnail::dispatch('element', $element->id, null, null, null, $seconds, true)
|
||||
: DeriveThumbnail::dispatch('element', $element->id, null, null, $shown->id, $seconds);
|
||||
$element->refresh();
|
||||
$this->pictureFeedback = $element->thumbnail_error
|
||||
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
|
||||
@@ -365,10 +368,24 @@ public function useOwnImage(): void
|
||||
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
|
||||
}
|
||||
|
||||
/** Ein Film ohne Inhaltsfassung, aber mit Website-Datei: die Filmstelle kommt aus dieser Datei. */
|
||||
public function hasWebsiteFilm(?ContentElement $element = null): bool
|
||||
{
|
||||
$element ??= $this->getRecord();
|
||||
|
||||
return $element->output_class === 'film'
|
||||
&& filled($element->preview_path)
|
||||
&& ! $element->versions()->exists();
|
||||
}
|
||||
|
||||
public function framePreviewUrl(): ?string
|
||||
{
|
||||
$shown = $this->shownVersion();
|
||||
|
||||
if (! $shown instanceof ContentElementVersion && $this->hasWebsiteFilm() && is_numeric($this->frameSecond) && trim($this->frameSecond) !== '') {
|
||||
return route('content.website-frame', ['element' => $this->getRecord(), 'sekunde' => $this->frameSecond]);
|
||||
}
|
||||
|
||||
if (! $shown instanceof ContentElementVersion || ! is_numeric($this->frameSecond) || trim($this->frameSecond) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
use App\Domain\Media\FilmPlayback;
|
||||
use App\Domain\Media\HlsPlaylist;
|
||||
use App\Domain\Media\MediaRendition;
|
||||
use App\Domain\Media\ThumbnailDeriver;
|
||||
use App\Http\Controllers\Concerns\ServesByteRanges;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -62,6 +63,24 @@ public function file(ContentElementVersion $version): StreamedResponse
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Einzelbild einer Stelle der Website-Datei, zur Auswahl des Vorschaubilds.
|
||||
*/
|
||||
public function websiteFrame(Request $request, ContentElement $element, ThumbnailDeriver $deriver): Response
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
$seconds = $request->query('sekunde');
|
||||
abort_unless(is_numeric($seconds), 404);
|
||||
|
||||
$bytes = $deriver->jpegAtWebsiteFile($element, (float) $seconds);
|
||||
abort_unless(is_string($bytes), 404);
|
||||
|
||||
return response($bytes, 200, [
|
||||
'Content-Type' => 'image/jpeg',
|
||||
'Cache-Control' => 'private, no-store',
|
||||
]);
|
||||
}
|
||||
|
||||
public function fileUrl(ContentElementVersion $version): ?string
|
||||
{
|
||||
return $this->storedPath($version) === null ? null : route('content.file', $version);
|
||||
|
||||
@@ -20,6 +20,7 @@ public function __construct(
|
||||
public readonly ?int $fromElement = null,
|
||||
public readonly ?int $versionId = null,
|
||||
public readonly ?float $atSecond = null,
|
||||
public readonly bool $websiteFile = false,
|
||||
) {}
|
||||
|
||||
public function handle(ThumbnailDeriver $deriver): void
|
||||
@@ -54,6 +55,12 @@ public function handle(ThumbnailDeriver $deriver): void
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->websiteFile && $this->atSecond !== null) {
|
||||
$deriver->forElementWebsiteFrame($element, $this->atSecond);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->versionId !== null && $this->atSecond !== null) {
|
||||
$version = ContentElementVersion::query()->find($this->versionId);
|
||||
|
||||
|
||||
Reference in new issue
Block a user