authorizeStaff(); $version->loadMissing('element'); return view('content.preview', [ 'version' => $version, 'fileUrl' => $this->fileUrl($version), 'pending' => $this->isPending($version), ]); } public function file(ContentElementVersion $version): StreamedResponse { $this->authorizeStaff(); $path = $this->storedPath($version); abort_unless(is_string($path), 404); return Storage::disk('media_derived')->response($path, basename($path), [ 'Content-Disposition' => 'inline', ]); } public function fileUrl(ContentElementVersion $version): ?string { return $this->storedPath($version) === null ? null : route('content.file', $version); } public function isPending(ContentElementVersion $version): bool { if ($this->storedPath($version) !== null) { return false; } $metadata = is_array($version->metadata) ? $version->metadata : []; $incoming = $metadata['incoming'] ?? null; return (is_string($incoming) && $incoming !== '') || is_array($incoming); } private function storedPath(ContentElementVersion $version): ?string { $file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null; if (! is_string($file) || $file === '' || str_contains($file, '..') || ! str_starts_with($file, 'inhalte/')) { return null; } return Storage::disk('media_derived')->exists($file) ? $file : null; } private function authorizeStaff(): void { $user = auth('staff')->user(); abort_unless( $user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)), 403, ); } }