Spiele Filme in allen Playern über die gespeicherte Qualitätsleiter.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8e77defaca
commit
1fb48783bf
14 files changed
+202
-18
No files matched your search
@@ -4,7 +4,11 @@
|
||||
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Domain\Media\FilmPlayback;
|
||||
use App\Domain\Media\HlsPlaylist;
|
||||
use App\Domain\Media\MediaRendition;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
@@ -39,6 +43,55 @@ public function fileUrl(ContentElementVersion $version): ?string
|
||||
return $this->storedPath($version) === null ? null : route('content.file', $version);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{mode: string, url: string}|null
|
||||
*/
|
||||
public function playback(ContentElementVersion $version): ?array
|
||||
{
|
||||
$version->loadMissing('element');
|
||||
|
||||
if ($version->element?->output_class !== 'film') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$mode = app(FilmPlayback::class)->mode($version->id);
|
||||
$master = MediaRendition::masterPath($version->id);
|
||||
|
||||
if ($mode === 'hls' && is_string($master)) {
|
||||
return [
|
||||
'mode' => 'hls',
|
||||
'url' => route('content.rendition', ['version' => $version, 'datei' => $master]),
|
||||
];
|
||||
}
|
||||
|
||||
$file = $this->fileUrl($version);
|
||||
|
||||
return $file === null ? null : ['mode' => 'file', 'url' => $file];
|
||||
}
|
||||
|
||||
public function rendition(ContentElementVersion $version, string $datei): Response|StreamedResponse
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
abort_unless($this->renditionBelongsTo($version->id, $datei), 404);
|
||||
$disk = Storage::disk('media_derived');
|
||||
abort_unless($disk->exists($datei), 404);
|
||||
|
||||
if (str_ends_with($datei, '.m3u8')) {
|
||||
$body = app(HlsPlaylist::class)->rewrite(
|
||||
$disk->get($datei),
|
||||
$datei,
|
||||
fn (string $target): string => route('content.rendition', ['version' => $version, 'datei' => $target]),
|
||||
);
|
||||
|
||||
return response($body, 200, [
|
||||
'Content-Type' => 'application/vnd.apple.mpegurl',
|
||||
'Cache-Control' => 'private, no-store',
|
||||
]);
|
||||
}
|
||||
|
||||
return $disk->response($datei, basename($datei), ['Content-Disposition' => 'inline']);
|
||||
}
|
||||
|
||||
public function isPending(ContentElementVersion $version): bool
|
||||
{
|
||||
if ($this->storedPath($version) !== null) {
|
||||
@@ -62,6 +115,13 @@ private function storedPath(ContentElementVersion $version): ?string
|
||||
return Storage::disk('media_derived')->exists($file) ? $file : null;
|
||||
}
|
||||
|
||||
private function renditionBelongsTo(int $versionId, string $path): bool
|
||||
{
|
||||
$prefix = 'ableitungen/'.$versionId;
|
||||
|
||||
return ($path === $prefix || str_starts_with($path, $prefix.'/')) && ! str_contains($path, '..');
|
||||
}
|
||||
|
||||
private function authorizeStaff(): void
|
||||
{
|
||||
$user = auth('staff')->user();
|
||||
|
||||
Reference in new issue
Block a user