Liefere Filme im Dateimodus und Downloads mit Bereichsabrufen aus und rechne die Prüfsumme einmal

LibraryController::fileResponse nutzt ServesByteRanges (206/416): Safari und iOS
spielen ab, Springen und Fortsetzen eines Downloads gehen. Dateiname und
attachment bleiben. Der Nachweis zählt einen vollständigen Abruf als eine
Auslieferung; Teilabrufe schreiben nur, wenn noch kein Eintrag der letzten zehn
Minuten steht. FileChecksum merkt die SHA-256 je Datei (Pfad, Größe, Zeit) und
wird beim Speichern vorgewärmt, damit die erste Wiedergabe nicht auf das
Hashen einer großen Datei wartet. Der entfernte decision-Schlüssel der
Artikelseite war ungenutzt.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
StommerandClaude Sonnet 5.5 committed 2026-12-01 11:12:58 +01:00
1 parent 9e8d0020b3
commit f07fbae940
6 files changed
+281 -24

No files matched your search

@@ -17,10 +17,12 @@
use App\Domain\Entitlement\Grant;
use App\Domain\Entitlement\GrantStatus;
use App\Domain\Media\DeliveryLog;
use App\Domain\Media\FileChecksum;
use App\Domain\Media\FilmPlayback;
use App\Domain\Media\HlsPlaylist;
use App\Domain\Media\MediaRendition;
use App\Domain\Media\StreamLifetime;
use App\Http\Controllers\Concerns\ServesByteRanges;
use App\Http\Controllers\Concerns\ServesImages;
use App\Http\Controllers\Controller;
use App\Http\CourseOutline;
@@ -40,6 +42,7 @@
class LibraryController extends Controller
{
use ServesByteRanges;
use ServesImages;
/** Inhaltsarten der Bibliothek (Schlüssel der Adresse und des Filters). */
@@ -252,9 +255,6 @@ public function show(Request $request, LicenseArticle $article): View
'action' => $action,
'allowed' => $decision->allowed,
'reason' => $decision->reason,
'decision' => is_numeric($metadata['decision_seconds'] ?? null)
? (int) $metadata['decision_seconds']
: null,
'playable' => $decision->allowed && is_string($file) && $file !== '' && ($class === 'film' || $class === 'audio'),
'playback' => app(FilmPlayback::class)->mode($version->id),
'renew_url' => $decision->allowed && $action === 'streamen' && app(FilmPlayback::class)->mode($version->id) === 'hls'
@@ -336,7 +336,7 @@ public function media(
]);
}
return $this->fileResponse($decision->grant, $article, $release, $version, $action, $file, 'bestand');
return $this->fileResponse($request, $decision->grant, $article, $release, $version, $action, $file, 'bestand');
}
public function rendition(
@@ -505,6 +505,7 @@ private function playlist(
}
private function fileResponse(
Request $request,
Grant $grant,
LicenseArticle $article,
ArticleRelease $release,
@@ -515,24 +516,27 @@ private function fileResponse(
): 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',
);
$log = app(DeliveryLog::class);
$checksum = fn (): ?string => app(FileChecksum::class)->of('media_derived', $file);
// Dateiname aus dem Anzeigetitel statt aus der Adresse („laden.mp4“); Laravel setzt Content-Disposition mit
// ASCII-Rückfall und UTF-8-Name.
return $disk->response(
// Ein vollständiger Abruf ist eine Auslieferung. Teilabrufe (Springen, Fortsetzen) derselben Wiedergabe zählen
// innerhalb der Laufzeit der Adresse nicht erneut; gibt es noch keinen Nachweis, entsteht genau einer.
if (is_string($request->header('Range'))) {
$log->writeUnlessRecent(600, $grant, $article, $release, $version, $action, $format, 'k0', $checksum);
$copy = '';
} else {
$copy = $log->write($grant, $article, $release, $version, $action, $format, $checksum(), 'k0')->copy_id;
}
// Dateiname aus dem Anzeigetitel statt aus der Adresse („laden.mp4“), mit ASCII-Rückfall und UTF-8-Name.
return $this->respondWithRanges(
$request,
'media_derived',
$file,
true,
$this->downloadName($version, $file),
['X-License-Copy' => $delivery->copy_id],
$action === 'laden' ? 'attachment' : 'inline',
$copy === '' ? [] : ['X-License-Copy' => $copy],
);
}