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
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user