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>
79 lines
2.5 KiB
PHP
79 lines
2.5 KiB
PHP
<?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,
|
|
?string $copyId = null,
|
|
?int $compositionVersionId = null,
|
|
): 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' => $copyId ?? self::newCopyId(),
|
|
'composition_version_id' => $compositionVersionId,
|
|
'checksum' => $checksum,
|
|
'marking' => $marking,
|
|
'delivered_at' => now(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Schreibt nur dann, wenn zu diesem Anspruch und dieser Fassung innerhalb des Zeitfensters noch kein Nachweis der
|
|
* Aktion steht. So zählt eine Wiedergabe einmal, auch wenn der Player nur Erneuerungen und Abschnitte abruft; ein
|
|
* Abruf, der nie die Hauptliste holt, bleibt trotzdem nicht ohne Nachweis.
|
|
*
|
|
* @return bool true, wenn geschrieben wurde
|
|
*/
|
|
public function writeUnlessRecent(
|
|
int $windowSeconds,
|
|
Grant $grant,
|
|
LicenseArticle $article,
|
|
ArticleRelease $release,
|
|
ContentElementVersion $version,
|
|
string $action,
|
|
string $format,
|
|
string $marking,
|
|
string|\Closure|null $checksum = null,
|
|
): bool {
|
|
$recent = MediaDelivery::query()
|
|
->where('grant_id', $grant->id)
|
|
->where('content_element_version_id', $version->id)
|
|
->where('action', $action)
|
|
->where('delivered_at', '>=', now()->subSeconds($windowSeconds))
|
|
->exists();
|
|
|
|
if ($recent) {
|
|
return false;
|
|
}
|
|
|
|
$this->write($grant, $article, $release, $version, $action, $format, $checksum instanceof \Closure ? $checksum() : $checksum, $marking);
|
|
|
|
return true;
|
|
}
|
|
|
|
public static function newCopyId(): string
|
|
{
|
|
return 'LK-'.strtoupper(bin2hex(random_bytes(6)));
|
|
}
|
|
}
|