Leite Vorschaubilder und Filmstufen geschuetzt ab
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d6ff881e4e
commit
c997eb500c
32 files changed
+979
-68
No files matched your search
@@ -44,6 +44,38 @@ public function explanation(): string
|
||||
};
|
||||
}
|
||||
|
||||
public function deskLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Kombination => 'Fachliche Kombination',
|
||||
self::Uebung => 'Modul',
|
||||
self::Kurs => 'Programm',
|
||||
};
|
||||
}
|
||||
|
||||
public function deskExplanation(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Kombination => $this->explanation(),
|
||||
self::Uebung => 'Ein Modul mit Lernziel, Zeit, Material und geordneten Bestandteilen. Dieselben Medien können in mehreren Modulen stecken.',
|
||||
self::Kurs => 'Ein Programm aus Modulen und weiteren Inhalten.',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function deskOptions(): array
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach (self::cases() as $case) {
|
||||
$options[$case->value] = $case->deskLabel();
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,9 @@ class MediaDelivery extends Model
|
||||
'content_element_version_id',
|
||||
'action',
|
||||
'format',
|
||||
'copy_id',
|
||||
'checksum',
|
||||
'marking',
|
||||
'delivered_at',
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Entitlement\MediaDelivery;
|
||||
|
||||
class DeliveryLog
|
||||
{
|
||||
public function write(
|
||||
Grant $grant,
|
||||
LicenseArticle $article,
|
||||
ArticleRelease $release,
|
||||
ContentElementVersion $version,
|
||||
string $action,
|
||||
string $format,
|
||||
?string $checksum,
|
||||
string $marking,
|
||||
): MediaDelivery {
|
||||
return MediaDelivery::query()->create([
|
||||
'grant_id' => $grant->id,
|
||||
'license_article_id' => $article->id,
|
||||
'article_release_id' => $release->id,
|
||||
'content_element_version_id' => $version->id,
|
||||
'action' => $action,
|
||||
'format' => $format,
|
||||
'copy_id' => 'LK-'.strtoupper(bin2hex(random_bytes(6))),
|
||||
'checksum' => $checksum,
|
||||
'marking' => $marking,
|
||||
'delivered_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class FfmpegFilmTranscoder implements FilmTranscoder
|
||||
{
|
||||
public function available(): bool
|
||||
{
|
||||
return (new ExecutableFinder)->find('ffmpeg') !== null;
|
||||
}
|
||||
|
||||
public function derive(int $versionId, string $sourceRelative): array
|
||||
{
|
||||
$binary = (new ExecutableFinder)->find('ffmpeg');
|
||||
|
||||
if ($binary === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$disk = Storage::disk('media_derived');
|
||||
$source = $disk->path($sourceRelative);
|
||||
$base = 'ableitungen/'.$versionId;
|
||||
$rows = [];
|
||||
|
||||
foreach ([480, 720, 1080] as $height) {
|
||||
$directory = $base.'/'.$height;
|
||||
$disk->makeDirectory($directory);
|
||||
$playlist = $disk->path($directory.'/index.m3u8');
|
||||
$segment = $disk->path($directory.'/segment_%03d.m4s');
|
||||
$process = new Process([
|
||||
$binary,
|
||||
'-y',
|
||||
'-i',
|
||||
$source,
|
||||
'-vf',
|
||||
'scale=-2:'.$height,
|
||||
'-c:v',
|
||||
'libx264',
|
||||
'-preset',
|
||||
'veryfast',
|
||||
'-crf',
|
||||
'23',
|
||||
'-c:a',
|
||||
'aac',
|
||||
'-hls_time',
|
||||
'6',
|
||||
'-hls_playlist_type',
|
||||
'vod',
|
||||
'-hls_segment_filename',
|
||||
$segment,
|
||||
$playlist,
|
||||
]);
|
||||
$process->setTimeout(3600);
|
||||
$process->run();
|
||||
|
||||
if (! $process->isSuccessful()) {
|
||||
throw new RuntimeException('Die Qualitätsstufe '.$height.' ließ sich nicht ableiten.');
|
||||
}
|
||||
|
||||
$rows[] = [
|
||||
'role' => 'variant',
|
||||
'label' => (string) $height,
|
||||
'path' => $directory.'/index.m3u8',
|
||||
];
|
||||
}
|
||||
|
||||
$master = "#EXTM3U\n#EXT-X-VERSION:3\n"
|
||||
."#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=854x480\n480/index.m3u8\n"
|
||||
."#EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720\n720/index.m3u8\n"
|
||||
."#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080\n1080/index.m3u8\n";
|
||||
$disk->put($base.'/master.m3u8', $master);
|
||||
$rows[] = ['role' => 'master', 'label' => 'master', 'path' => $base.'/master.m3u8'];
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
interface FilmTranscoder
|
||||
{
|
||||
public function available(): bool;
|
||||
|
||||
/**
|
||||
* @return list<array{role: string, label: string, path: string}>
|
||||
*/
|
||||
public function derive(int $versionId, string $sourceRelative): array;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
class HlsPlaylist
|
||||
{
|
||||
public function rewrite(string $playlist, string $playlistPath, callable $sign): string
|
||||
{
|
||||
$directory = str_replace('\\', '/', dirname($playlistPath));
|
||||
$lines = preg_split("/\r\n|\n|\r/", $playlist) ?: [];
|
||||
$rewritten = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$value = trim($line);
|
||||
|
||||
if ($value === '' || str_starts_with($value, '#')) {
|
||||
$rewritten[] = $line;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$target = str_starts_with($value, 'ableitungen/')
|
||||
? $value
|
||||
: ($directory === '.' ? $value : $directory.'/'.$value);
|
||||
$rewritten[] = $sign($target);
|
||||
}
|
||||
|
||||
return implode("\n", $rewritten)."\n";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MediaRendition extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'content_element_version_id',
|
||||
'role',
|
||||
'label',
|
||||
'path',
|
||||
];
|
||||
|
||||
public static function masterPath(int $versionId): ?string
|
||||
{
|
||||
$path = static::query()
|
||||
->where('content_element_version_id', $versionId)
|
||||
->where('role', 'master')
|
||||
->value('path');
|
||||
|
||||
return is_string($path) && $path !== '' ? $path : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class ThumbnailDeriver
|
||||
{
|
||||
public function forElement(ContentElement $element): void
|
||||
{
|
||||
$version = $element->versions()->orderByDesc('number')->first();
|
||||
$file = is_array($version?->metadata) ? ($version->metadata['file'] ?? null) : null;
|
||||
|
||||
if (! $version instanceof ContentElementVersion || ! is_string($file) || $file === '') {
|
||||
$this->fail($element, 'Für dieses Medium liegt noch keine Datei vor.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array($element->output_class, ['film', 'audio'], true)) {
|
||||
$this->frame($element, $file);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->still($element, Storage::disk('media_derived'), $file, 'element-'.$element->id);
|
||||
}
|
||||
|
||||
public function forCompositionUpload(Composition $composition, string $incoming): void
|
||||
{
|
||||
if (! str_starts_with($incoming, 'vorschau/') || str_contains($incoming, '..')) {
|
||||
$this->failComposition($composition, 'Das Vorschaubild wurde nicht übernommen.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->still($composition, Storage::disk('cms_incoming'), $incoming, 'komposition-'.$composition->id);
|
||||
}
|
||||
|
||||
private function frame(ContentElement $element, string $file): void
|
||||
{
|
||||
$binary = (new ExecutableFinder)->find('ffmpeg');
|
||||
$disk = Storage::disk('media_derived');
|
||||
|
||||
if ($binary === null || ! $disk->exists($file)) {
|
||||
$this->fail($element, 'Für dieses Medium liegt noch kein abgeleitetes Vorschaubild vor.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$target = 'vorschau/element-'.$element->id.'.jpg';
|
||||
$disk->makeDirectory('vorschau');
|
||||
$process = new Process([
|
||||
$binary,
|
||||
'-y',
|
||||
'-ss',
|
||||
'0',
|
||||
'-i',
|
||||
$disk->path($file),
|
||||
'-frames:v',
|
||||
'1',
|
||||
$disk->path($target),
|
||||
]);
|
||||
$process->setTimeout(120);
|
||||
$process->run();
|
||||
|
||||
if (! $process->isSuccessful() || ! $disk->exists($target)) {
|
||||
$this->fail($element, 'Aus der Filmdatei ließ sich kein Vorschaubild erzeugen.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$element->thumbnail_path = $target;
|
||||
$element->thumbnail_alt = $element->working_title;
|
||||
$element->thumbnail_error = null;
|
||||
$element->save();
|
||||
}
|
||||
|
||||
private function still(ContentElement|Composition $subject, Filesystem $disk, string $file, string $name): void
|
||||
{
|
||||
if (! $disk->exists($file)) {
|
||||
$this->failSubject($subject, 'Die Bilddatei wurde nicht gefunden.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$image = @imagecreatefromstring($disk->get($file));
|
||||
|
||||
if ($image === false) {
|
||||
$this->failSubject($subject, 'Die Bilddatei ließ sich nicht lesen.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$width = imagesx($image);
|
||||
$height = imagesy($image);
|
||||
$targetWidth = 640;
|
||||
$targetHeight = (int) max(1, round($height * ($targetWidth / max(1, $width))));
|
||||
$canvas = imagecreatetruecolor($targetWidth, $targetHeight);
|
||||
imagecopyresampled($canvas, $image, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height);
|
||||
ob_start();
|
||||
imagejpeg($canvas, null, 82);
|
||||
$bytes = ob_get_clean();
|
||||
imagedestroy($image);
|
||||
imagedestroy($canvas);
|
||||
|
||||
if (! is_string($bytes) || $bytes === '') {
|
||||
$this->failSubject($subject, 'Das Vorschaubild ließ sich nicht schreiben.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$path = 'vorschau/'.$name.'.jpg';
|
||||
Storage::disk('media_derived')->put($path, $bytes);
|
||||
$subject->thumbnail_path = $path;
|
||||
$subject->thumbnail_alt = $subject instanceof Composition ? $subject->designation : $subject->working_title;
|
||||
$subject->thumbnail_error = null;
|
||||
$subject->save();
|
||||
}
|
||||
|
||||
private function fail(ContentElement $element, string $reason): void
|
||||
{
|
||||
$this->failSubject($element, $reason);
|
||||
}
|
||||
|
||||
private function failComposition(Composition $composition, string $reason): void
|
||||
{
|
||||
$this->failSubject($composition, $reason);
|
||||
}
|
||||
|
||||
private function failSubject(ContentElement|Composition $subject, string $reason): void
|
||||
{
|
||||
$subject->thumbnail_error = $reason;
|
||||
$subject->save();
|
||||
}
|
||||
}
|
||||
@@ -65,8 +65,8 @@ public function form(Schema $schema): Schema
|
||||
Textarea::make('material_note')->label('Materialbedarf')->rows(2),
|
||||
Placeholder::make('status')->label('Stand')->content(fn (): HtmlString => new HtmlString(e($this->statusText()))),
|
||||
Placeholder::make('outline')->label('Gliederung der aktuellen Fassung')->content(fn (): HtmlString => new HtmlString($this->outlineHtml())),
|
||||
Select::make('kind')->label('Art')->options(CompositionKind::options())->required()
|
||||
->helperText('Übung, Kurs und fachliche Kombination sind verschiedene Zusammenstellungen. Die Art lässt sich hier ändern.'),
|
||||
Select::make('kind')->label('Zusammenstellung')->options(CompositionKind::deskOptions())->required()
|
||||
->helperText('Programm, Modul oder fachliche Kombination. Die Inhaltsart steuert die Bibliothek. Die gespeicherte Herkunft bleibt bestehen.'),
|
||||
Select::make('editorial_content_kind_id')
|
||||
->label('Inhaltsart')
|
||||
->options(fn (): array => EditorialContentKind::selectOptions())
|
||||
|
||||
@@ -20,7 +20,7 @@ abstract protected function kind(): CompositionKind;
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return $this->kind()->explanation();
|
||||
return $this->kind()->deskExplanation();
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Domain\Catalog\ArticleRelease;
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\EditorialDimension;
|
||||
use App\Domain\Catalog\IdentityDimension;
|
||||
@@ -11,12 +12,15 @@
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use App\Domain\Entitlement\MediaDelivery;
|
||||
use App\Domain\Media\DeliveryLog;
|
||||
use App\Domain\Media\HlsPlaylist;
|
||||
use App\Domain\Media\MediaRendition;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\CourseOutline;
|
||||
use App\Http\LibraryCatalog;
|
||||
use App\Http\SignedLink;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
@@ -142,6 +146,7 @@ public function show(Request $request, LicenseArticle $article): View
|
||||
? (int) $metadata['decision_seconds']
|
||||
: null,
|
||||
'playable' => $decision->allowed && is_string($file) && $file !== '' && ($class === 'film' || $class === 'audio'),
|
||||
'playback' => MediaRendition::masterPath($version->id) !== null ? 'hls' : 'file',
|
||||
'pillars' => $version->element->pillars->pluck('name')->all(),
|
||||
'url' => $decision->allowed
|
||||
? SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
@@ -171,42 +176,90 @@ public function media(
|
||||
ArticleRelease $release,
|
||||
ContentElementVersion $version,
|
||||
string $action,
|
||||
): View|StreamedResponse {
|
||||
): View|StreamedResponse|Response {
|
||||
abort_unless(in_array($action, ['ansehen', 'streamen', 'laden'], true), 404);
|
||||
abort_unless((int) $request->query('reader') === $request->user()->id, 403);
|
||||
|
||||
$decision = app(DecideAccess::class)($request->user(), $article, $release, $version, $action);
|
||||
abort_unless($decision->allowed, 403, $decision->reason);
|
||||
|
||||
if ($decision->grant !== null) {
|
||||
MediaDelivery::query()->create([
|
||||
'grant_id' => $decision->grant->id,
|
||||
'license_article_id' => $article->id,
|
||||
'article_release_id' => $release->id,
|
||||
'content_element_version_id' => $version->id,
|
||||
'action' => $action,
|
||||
'format' => 'bestand',
|
||||
'delivered_at' => now(),
|
||||
]);
|
||||
}
|
||||
abort_unless($decision->allowed && $decision->grant !== null, 403, $decision->reason);
|
||||
|
||||
$version->loadMissing('element');
|
||||
$master = $action === 'streamen' ? MediaRendition::masterPath($version->id) : null;
|
||||
|
||||
if (is_string($master)) {
|
||||
return $this->playlist($request, $article, $release, $version, $decision->grant, $master);
|
||||
}
|
||||
|
||||
$file = $version->metadata['file'] ?? null;
|
||||
|
||||
if (! is_string($file) || $file === '' || str_contains($file, '..')) {
|
||||
$delivery = app(DeliveryLog::class)->write(
|
||||
$decision->grant,
|
||||
$article,
|
||||
$release,
|
||||
$version,
|
||||
$action,
|
||||
'text',
|
||||
hash('sha256', (string) $version->body),
|
||||
'k2',
|
||||
);
|
||||
|
||||
return view('member.read', [
|
||||
'article' => $article,
|
||||
'version' => $version,
|
||||
'license' => $decision->grant?->rights_snapshot['purpose'] ?? null,
|
||||
'license' => $decision->grant->rights_snapshot['purpose'] ?? null,
|
||||
'reader' => $request->user()->name,
|
||||
'copy' => $delivery->copy_id,
|
||||
]);
|
||||
}
|
||||
|
||||
$disk = Storage::disk('media_derived');
|
||||
abort_unless($disk->exists($file), 404);
|
||||
return $this->fileResponse($decision->grant, $article, $release, $version, $action, $file, 'bestand');
|
||||
}
|
||||
|
||||
return $disk->response($file, basename($file), [
|
||||
'Content-Disposition' => $action === 'laden' ? 'attachment' : 'inline',
|
||||
]);
|
||||
public function rendition(
|
||||
Request $request,
|
||||
LicenseArticle $article,
|
||||
ArticleRelease $release,
|
||||
ContentElementVersion $version,
|
||||
string $datei,
|
||||
): Response|StreamedResponse {
|
||||
abort_unless((int) $request->query('reader') === $request->user()->id, 403);
|
||||
abort_unless($this->renditionBelongsTo($version->id, $datei), 404);
|
||||
|
||||
$decision = app(DecideAccess::class)($request->user(), $article, $release, $version, 'streamen');
|
||||
abort_unless($decision->allowed && $decision->grant !== null, 403, $decision->reason);
|
||||
|
||||
if (str_ends_with($datei, '.m3u8')) {
|
||||
return $this->playlist(
|
||||
$request,
|
||||
$article,
|
||||
$release,
|
||||
$version,
|
||||
$decision->grant,
|
||||
$datei,
|
||||
str_ends_with($datei, 'master.m3u8'),
|
||||
);
|
||||
}
|
||||
|
||||
$disk = Storage::disk('media_derived');
|
||||
abort_unless($disk->exists($datei), 404);
|
||||
|
||||
return $disk->response($datei, basename($datei), ['Content-Disposition' => 'inline']);
|
||||
}
|
||||
|
||||
public function thumbnail(Request $request, string $kind, int $subject): StreamedResponse
|
||||
{
|
||||
abort_unless(in_array($kind, ['komposition', 'element'], true), 404);
|
||||
$model = $kind === 'komposition'
|
||||
? Composition::query()->findOrFail($subject)
|
||||
: ContentElement::query()->findOrFail($subject);
|
||||
$path = $model->thumbnail_path;
|
||||
abort_unless(is_string($path) && str_starts_with($path, 'vorschau/') && ! str_contains($path, '..'), 404);
|
||||
abort_unless($this->maySeeThumbnail($request, $kind, $subject), 403);
|
||||
$disk = Storage::disk('media_derived');
|
||||
abort_unless($disk->exists($path), 404);
|
||||
|
||||
return $disk->response($path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,6 +272,111 @@ private function matches(array $card, string $query): bool
|
||||
return str_contains($haystack, mb_strtolower($query));
|
||||
}
|
||||
|
||||
private function playlist(
|
||||
Request $request,
|
||||
LicenseArticle $article,
|
||||
ArticleRelease $release,
|
||||
ContentElementVersion $version,
|
||||
Grant $grant,
|
||||
string $path,
|
||||
bool $record = true,
|
||||
): Response {
|
||||
abort_unless($this->renditionBelongsTo($version->id, $path), 404);
|
||||
$disk = Storage::disk('media_derived');
|
||||
abort_unless($disk->exists($path), 404);
|
||||
$rewritten = app(HlsPlaylist::class)->rewrite(
|
||||
$disk->get($path),
|
||||
$path,
|
||||
fn (string $target): string => SignedLink::temporary('member.rendition', now()->addMinutes(10), [
|
||||
'article' => $article->id,
|
||||
'release' => $release->id,
|
||||
'version' => $version->id,
|
||||
'datei' => $target,
|
||||
'reader' => $request->user()->id,
|
||||
]),
|
||||
);
|
||||
$copy = '';
|
||||
|
||||
if ($record) {
|
||||
$delivery = app(DeliveryLog::class)->write(
|
||||
$grant,
|
||||
$article,
|
||||
$release,
|
||||
$version,
|
||||
'streamen',
|
||||
'hls',
|
||||
hash('sha256', $rewritten),
|
||||
'k0',
|
||||
);
|
||||
$copy = $delivery->copy_id;
|
||||
}
|
||||
|
||||
return response($rewritten, 200, [
|
||||
'Content-Type' => 'application/vnd.apple.mpegurl',
|
||||
'X-License-Copy' => $copy,
|
||||
]);
|
||||
}
|
||||
|
||||
private function fileResponse(
|
||||
Grant $grant,
|
||||
LicenseArticle $article,
|
||||
ArticleRelease $release,
|
||||
ContentElementVersion $version,
|
||||
string $action,
|
||||
string $file,
|
||||
string $format,
|
||||
): StreamedResponse {
|
||||
$disk = Storage::disk('media_derived');
|
||||
abort_unless($disk->exists($file) && ! str_contains($file, '..'), 404);
|
||||
$delivery = app(DeliveryLog::class)->write(
|
||||
$grant,
|
||||
$article,
|
||||
$release,
|
||||
$version,
|
||||
$action,
|
||||
$format,
|
||||
hash_file('sha256', $disk->path($file)) ?: null,
|
||||
'k0',
|
||||
);
|
||||
|
||||
return $disk->response($file, basename($file), [
|
||||
'Content-Disposition' => $action === 'laden' ? 'attachment' : 'inline',
|
||||
'X-License-Copy' => $delivery->copy_id,
|
||||
]);
|
||||
}
|
||||
|
||||
private function renditionBelongsTo(int $versionId, string $path): bool
|
||||
{
|
||||
$prefix = 'ableitungen/'.$versionId;
|
||||
|
||||
return ($path === $prefix || str_starts_with($path, $prefix.'/')) && ! str_contains($path, '..');
|
||||
}
|
||||
|
||||
private function maySeeThumbnail(Request $request, string $kind, int $subject): bool
|
||||
{
|
||||
$grants = $this->grantQuery($request)->with('article.currentRelease.contents.elementVersion', 'article.currentRelease.rootCompositionVersion')->get();
|
||||
|
||||
foreach ($grants as $grant) {
|
||||
$release = $grant->article->currentRelease;
|
||||
|
||||
if ($release === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($kind === 'komposition' && $release->rootCompositionVersion?->composition_id === $subject) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($kind === 'element' && $release->contents->contains(
|
||||
fn ($content): bool => $content->elementVersion?->content_element_id === $subject,
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function grantQuery(Request $request)
|
||||
{
|
||||
return Grant::query()
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
use App\Domain\Entitlement\DecideAccess;
|
||||
use App\Domain\Entitlement\Grant;
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use App\Domain\Media\MediaRendition;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -117,9 +118,12 @@ private function present(User $user, StructureNode $node): array
|
||||
$view = null;
|
||||
$download = null;
|
||||
|
||||
$playback = 'file';
|
||||
|
||||
if ($node->contentElementVersionId !== null) {
|
||||
$view = $this->open($user, $node->contentElementVersionId, $this->viewAction($node->outputClass));
|
||||
$download = $this->open($user, $node->contentElementVersionId, 'laden');
|
||||
$playback = MediaRendition::masterPath($node->contentElementVersionId) !== null ? 'hls' : 'file';
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -127,6 +131,7 @@ private function present(User $user, StructureNode $node): array
|
||||
'title' => $node->title,
|
||||
'kind' => $node->editorialKindLabel ?? $node->technicalKindLabel,
|
||||
'output_class' => $node->outputClass,
|
||||
'playback' => $playback,
|
||||
'view_url' => $view,
|
||||
'download_url' => $download,
|
||||
'program_url' => $this->programUrl($node),
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Media\FilmTranscoder;
|
||||
use App\Domain\Media\MediaRendition;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Throwable;
|
||||
|
||||
class DeriveFilmRenditions implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public int $timeout = 3600;
|
||||
|
||||
public function __construct(public readonly int $versionId) {}
|
||||
|
||||
public function handle(FilmTranscoder $transcoder): void
|
||||
{
|
||||
$version = ContentElementVersion::query()->with('element')->find($this->versionId);
|
||||
$file = is_array($version?->metadata) ? ($version->metadata['file'] ?? null) : null;
|
||||
|
||||
if ($version === null || $version->element->output_class !== 'film' || ! is_string($file) || $file === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $transcoder->available()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$rows = $transcoder->derive($version->id, $file);
|
||||
} catch (Throwable) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($rows as $row) {
|
||||
MediaRendition::query()->updateOrCreate(
|
||||
[
|
||||
'content_element_version_id' => $version->id,
|
||||
'label' => $row['label'],
|
||||
],
|
||||
[
|
||||
'role' => $row['role'],
|
||||
'path' => $row['path'],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Media\ThumbnailDeriver;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
|
||||
class DeriveThumbnail implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
public readonly string $subject,
|
||||
public readonly int $subjectId,
|
||||
public readonly ?string $incoming = null,
|
||||
) {}
|
||||
|
||||
public function handle(ThumbnailDeriver $deriver): void
|
||||
{
|
||||
if ($this->subject === 'komposition') {
|
||||
$composition = Composition::query()->find($this->subjectId);
|
||||
|
||||
if ($composition !== null && is_string($this->incoming)) {
|
||||
$deriver->forCompositionUpload($composition, $this->incoming);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$element = ContentElement::query()->find($this->subjectId);
|
||||
|
||||
if ($element !== null) {
|
||||
$deriver->forElement($element);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,8 @@ public function handle(): void
|
||||
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
$version->status = ContentVersionStatus::Bereit;
|
||||
$version->save();
|
||||
DeriveThumbnail::dispatch('element', $version->content_element_id);
|
||||
DeriveFilmRenditions::dispatch($version->id);
|
||||
}
|
||||
|
||||
private function storedName(string $name): ?string
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
use App\Domain\Cms\NavigationItemPolicy;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PagePolicy;
|
||||
use App\Domain\Media\FfmpegFilmTranscoder;
|
||||
use App\Domain\Media\FilmTranscoder;
|
||||
use App\Filament\Support\MediaUploadLimit;
|
||||
use App\Http\Responses\StaffLoginResponse;
|
||||
use App\Models\User;
|
||||
@@ -19,7 +21,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
$this->app->bind(FilmTranscoder::class, FfmpegFilmTranscoder::class);
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
|
||||
Reference in new issue
Block a user