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));
|
$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
|
public function forCompositionUpload(Composition $composition, string $incoming): void
|
||||||
{
|
{
|
||||||
if (! str_starts_with($incoming, 'vorschau/') || str_contains($incoming, '..')) {
|
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);
|
$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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -266,8 +266,9 @@ public function adoptFrame(): void
|
|||||||
/** @var ContentElement $element */
|
/** @var ContentElement $element */
|
||||||
$element = $this->getRecord();
|
$element = $this->getRecord();
|
||||||
$shown = $this->shownVersion();
|
$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.';
|
$this->pictureFeedback = 'Für dieses Medium gibt es keine Filmstelle.';
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -290,7 +291,9 @@ public function adoptFrame(): void
|
|||||||
$this->keepAlt($element);
|
$this->keepAlt($element);
|
||||||
$element->thumbnail_error = null;
|
$element->thumbnail_error = null;
|
||||||
$element->save();
|
$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();
|
$element->refresh();
|
||||||
$this->pictureFeedback = $element->thumbnail_error
|
$this->pictureFeedback = $element->thumbnail_error
|
||||||
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
|
?: '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.';
|
?: '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
|
public function framePreviewUrl(): ?string
|
||||||
{
|
{
|
||||||
$shown = $this->shownVersion();
|
$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) === '') {
|
if (! $shown instanceof ContentElementVersion || ! is_numeric($this->frameSecond) || trim($this->frameSecond) === '') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
use App\Domain\Media\FilmPlayback;
|
use App\Domain\Media\FilmPlayback;
|
||||||
use App\Domain\Media\HlsPlaylist;
|
use App\Domain\Media\HlsPlaylist;
|
||||||
use App\Domain\Media\MediaRendition;
|
use App\Domain\Media\MediaRendition;
|
||||||
|
use App\Domain\Media\ThumbnailDeriver;
|
||||||
use App\Http\Controllers\Concerns\ServesByteRanges;
|
use App\Http\Controllers\Concerns\ServesByteRanges;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
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
|
public function fileUrl(ContentElementVersion $version): ?string
|
||||||
{
|
{
|
||||||
return $this->storedPath($version) === null ? null : route('content.file', $version);
|
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 $fromElement = null,
|
||||||
public readonly ?int $versionId = null,
|
public readonly ?int $versionId = null,
|
||||||
public readonly ?float $atSecond = null,
|
public readonly ?float $atSecond = null,
|
||||||
|
public readonly bool $websiteFile = false,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function handle(ThumbnailDeriver $deriver): void
|
public function handle(ThumbnailDeriver $deriver): void
|
||||||
@@ -54,6 +55,12 @@ public function handle(ThumbnailDeriver $deriver): void
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->websiteFile && $this->atSecond !== null) {
|
||||||
|
$deriver->forElementWebsiteFrame($element, $this->atSecond);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->versionId !== null && $this->atSecond !== null) {
|
if ($this->versionId !== null && $this->atSecond !== null) {
|
||||||
$version = ContentElementVersion::query()->find($this->versionId);
|
$version = ContentElementVersion::query()->find($this->versionId);
|
||||||
|
|
||||||
|
|||||||
@@ -248,7 +248,7 @@
|
|||||||
@if ($canRevise)
|
@if ($canRevise)
|
||||||
<aside class="vw-medien-seite" aria-labelledby="bildwahl-titel">
|
<aside class="vw-medien-seite" aria-labelledby="bildwahl-titel">
|
||||||
<h2 id="bildwahl-titel" class="vw-abschnitt-titel">Vorschaubild ändern</h2>
|
<h2 id="bildwahl-titel" class="vw-abschnitt-titel">Vorschaubild ändern</h2>
|
||||||
@php $ausFilm = $element->output_class === 'film' && $shown; @endphp
|
@php $ausWebsiteDatei = ! $shown && $this->hasWebsiteFilm(); $ausFilm = $element->output_class === 'film' && ($shown || $ausWebsiteDatei); @endphp
|
||||||
@if ($ausFilm)
|
@if ($ausFilm)
|
||||||
<div class="vw-segment" role="group" aria-label="Quelle des Vorschaubilds">
|
<div class="vw-segment" role="group" aria-label="Quelle des Vorschaubilds">
|
||||||
<button type="button" wire:click="$set('bildQuelle', 'film')" aria-pressed="{{ $this->bildQuelle === 'film' ? 'true' : 'false' }}">Stelle aus dem Film</button>
|
<button type="button" wire:click="$set('bildQuelle', 'film')" aria-pressed="{{ $this->bildQuelle === 'film' ? 'true' : 'false' }}">Stelle aus dem Film</button>
|
||||||
@@ -256,11 +256,11 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@if ($ausFilm && $this->bildQuelle === 'film')
|
@if ($ausFilm && $this->bildQuelle === 'film')
|
||||||
<p class="vw-feld-hilfe">Aus Fassung {{ $shown->number }}. Die Vorschau nimmt die kleine Filmstufe, sofern sie vorliegt. Die Filmdatei bleibt unverändert.</p>
|
<p class="vw-feld-hilfe">@if ($shown)Aus Fassung {{ $shown->number }}. Die Vorschau nimmt die kleine Filmstufe, sofern sie vorliegt.@else Aus der Website-Datei dieses Mediums.@endif Die Filmdatei bleibt unverändert.</p>
|
||||||
{{-- Regler und Zahl zeigen immer denselben Wert; übernommen wird genau die angezeigte Stelle. --}}
|
{{-- Regler und Zahl zeigen immer denselben Wert; übernommen wird genau die angezeigte Stelle. --}}
|
||||||
@php
|
@php
|
||||||
// Ohne eigene Wahl beginnt der Regler bei der Stelle des aktuellen Vorschaubilds aus dieser Fassung.
|
// Ohne eigene Wahl beginnt der Regler bei der Stelle des aktuellen Vorschaubilds aus dieser Fassung.
|
||||||
$aktuelleStelle = preg_match('/^frame:'.$shown->id.'@([\d.]+)$/', (string) $element->thumbnail_source, $treffer) === 1 ? $treffer[1] : '0';
|
$aktuelleStelle = preg_match('/^frame:'.($shown?->id ?? 0).'@([\d.]+)$/', (string) $element->thumbnail_source, $treffer) === 1 ? $treffer[1] : '0';
|
||||||
@endphp
|
@endphp
|
||||||
<div x-data="{ second: {{ json_encode($this->frameSecond !== '' ? $this->frameSecond : $aktuelleStelle) }} }" style="display: grid; gap: 0.4rem;">
|
<div x-data="{ second: {{ json_encode($this->frameSecond !== '' ? $this->frameSecond : $aktuelleStelle) }} }" style="display: grid; gap: 0.4rem;">
|
||||||
<label class="vw-feldlabel" for="filmstelle">Zeitposition in Sekunden</label>
|
<label class="vw-feldlabel" for="filmstelle">Zeitposition in Sekunden</label>
|
||||||
|
|||||||
@@ -84,6 +84,10 @@
|
|||||||
->middleware('auth:staff')
|
->middleware('auth:staff')
|
||||||
->whereNumber('element')
|
->whereNumber('element')
|
||||||
->name('content.website-file');
|
->name('content.website-file');
|
||||||
|
Route::get('/redaktion/website-datei/{element}/bild', [ContentPreviewController::class, 'websiteFrame'])
|
||||||
|
->middleware('auth:staff')
|
||||||
|
->whereNumber('element')
|
||||||
|
->name('content.website-frame');
|
||||||
Route::get('/redaktion/inhalt/{version}', [ContentPreviewController::class, 'show'])
|
Route::get('/redaktion/inhalt/{version}', [ContentPreviewController::class, 'show'])
|
||||||
->middleware('auth:staff')
|
->middleware('auth:staff')
|
||||||
->name('content.preview');
|
->name('content.preview');
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
use App\Domain\Catalog\DomainRuleException;
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
use App\Domain\Entitlement\Grant;
|
use App\Domain\Entitlement\Grant;
|
||||||
use App\Domain\Media\PresentationFile;
|
use App\Domain\Media\PresentationFile;
|
||||||
|
use App\Domain\Media\ThumbnailDeriver;
|
||||||
use App\Domain\Media\WebsiteMedia;
|
use App\Domain\Media\WebsiteMedia;
|
||||||
use App\Domain\Media\WebsiteRelease;
|
use App\Domain\Media\WebsiteRelease;
|
||||||
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
||||||
@@ -186,6 +187,54 @@ public function test_a_versionless_film_shows_its_website_file_in_the_media_mana
|
|||||||
$this->get($url, ['Range' => 'bytes=50-60'])->assertStatus(416);
|
$this->get($url, ['Range' => 'bytes=50-60'])->assertStatus(416);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_a_film_frame_of_the_website_file_becomes_the_preview_image(): void
|
||||||
|
{
|
||||||
|
$image = imagecreatetruecolor(4, 4);
|
||||||
|
ob_start();
|
||||||
|
imagejpeg($image);
|
||||||
|
$jpeg = ob_get_clean();
|
||||||
|
imagedestroy($image);
|
||||||
|
$this->app->bind(ThumbnailDeriver::class, fn () => new class($jpeg) extends ThumbnailDeriver
|
||||||
|
{
|
||||||
|
public function __construct(private string $jpeg) {}
|
||||||
|
|
||||||
|
public function jpegAtWebsiteFile(ContentElement $element, float $seconds): ?string
|
||||||
|
{
|
||||||
|
return $this->jpeg;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$film = app(ContentService::class)->createElement('film', 'film', 'Trailer');
|
||||||
|
$film->preview_path = 'teaser/'.$film->id.'/datei.mp4';
|
||||||
|
$film->save();
|
||||||
|
Storage::disk('media_derived')->put($film->preview_path, 'x');
|
||||||
|
$this->actingAs($this->editor(), 'staff');
|
||||||
|
|
||||||
|
Livewire::test(ViewContentElement::class, ['record' => $film->getKey()])
|
||||||
|
->set('bereich', 'vorschaubild')
|
||||||
|
->assertSee('Diese Stelle übernehmen')
|
||||||
|
->assertSee('Aus der Website-Datei')
|
||||||
|
->set('frameSecond', '12.5')
|
||||||
|
->call('adoptFrame')
|
||||||
|
->assertSet('pictureFeedback', 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.');
|
||||||
|
|
||||||
|
$film->refresh();
|
||||||
|
$this->assertSame('vorschau/element-'.$film->id.'.jpg', $film->thumbnail_path);
|
||||||
|
$this->assertSame('frame:0@12.5', $film->thumbnail_source);
|
||||||
|
$this->assertSame(0, $film->versions()->count());
|
||||||
|
Storage::disk('media_derived')->assertExists($film->thumbnail_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_frame_of_the_website_file_is_only_available_to_editors_and_for_a_film_with_a_file(): void
|
||||||
|
{
|
||||||
|
$film = app(ContentService::class)->createElement('film', 'film', 'Ohne Datei');
|
||||||
|
|
||||||
|
$this->get(route('content.website-frame', ['element' => $film, 'sekunde' => 3]))->assertRedirect();
|
||||||
|
|
||||||
|
$this->actingAs($this->editor(), 'staff');
|
||||||
|
$this->get(route('content.website-frame', ['element' => $film, 'sekunde' => 3]))->assertNotFound();
|
||||||
|
$this->get(route('content.website-frame', ['element' => $film]))->assertNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
public function test_the_website_file_is_not_served_to_guests_or_without_a_file(): void
|
public function test_the_website_file_is_not_served_to_guests_or_without_a_file(): void
|
||||||
{
|
{
|
||||||
Storage::disk('media_derived')->put('teaser/1/datei.mp4', 'x');
|
Storage::disk('media_derived')->put('teaser/1/datei.mp4', 'x');
|
||||||
|
|||||||
Reference in new issue
Block a user