load($request, $article, $release, $path); $copy = DeliveryLog::newCopyId(); $shown = false; foreach ($guide['chapters'] as $chapter) { if ($chapter['allowed'] && $chapter['grant'] !== null) { app(DeliveryLog::class)->write($chapter['grant'], $article, $release, $chapter['version'], 'ansehen', 'text', hash('sha256', (string) $chapter['version']->body), 'k2', $copy, $located['version']->id); $shown = true; } } return view('member.document', [ 'guide' => $guide, 'reader' => $request->user()->name, 'copy' => $shown ? $copy : null, 'pdfUrl' => app(DocumentGuide::class)->pdfAllowed($guide) ? SignedLink::temporary('member.document.pdf', now()->addMinutes(10), [ 'article' => $article->id, 'release' => $release->id, 'path' => $path, 'reader' => $request->user()->id, ]) : null, ]); } public function pdf(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): Response { abort_unless((int) $request->query('reader') === $request->user()->id, 403); [$guide, $located] = $this->load($request, $article, $release, $path); abort_unless(app(DocumentGuide::class)->pdfAllowed($guide), 403, 'Für dieses PDF fehlt die Berechtigung für ein Kapitel.'); $copy = DeliveryLog::newCopyId(); $images = app(EmbeddedImages::class)->forPdf($request->user(), $article, $release); $content = app(DocumentPdf::class)->render($guide, $request->user()->name, $copy, $images); $checksum = hash('sha256', $content); foreach ($guide['chapters'] as $chapter) { $grant = $chapter['download_grant'] ?? $chapter['grant']; if ($grant !== null) { app(DeliveryLog::class)->write($grant, $article, $release, $chapter['version'], 'laden', 'pdf', $checksum, 'k2', $copy, $located['version']->id); } } foreach ($images->used() as $image) { app(DeliveryLog::class)->write($image['grant'], $article, $release, $image['version'], 'laden', 'pdf', $checksum, 'k2', $copy, $located['version']->id); } return response($content, 200, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="'.(str($guide['title'])->slug()->value() ?: 'dokument').'.pdf"', 'X-License-Copy' => $copy, 'Cache-Control' => 'private, no-store', ]); } /** * @return array{0: array, 1: array{version: CompositionVersion, selection: list|null}} */ private function load(Request $request, LicenseArticle $article, ArticleRelease $release, string $path): array { $guides = app(ExerciseGuide::class); abort_unless($guides->mayOpen($request->user(), $article, $release), 403); $located = $guides->locate($release, $path, CompositionKind::Document); abort_if($located === null, 404); return [app(DocumentGuide::class)->build($request->user(), $article, $release, $located['version']), $located]; } }