Zeige Medienfassungen in der Verwaltung und halte Beschreibungen davon getrennt.
Eine Fassung bleibt nummeriert und kann deaktiviert werden. Beschreibung und fachliche Säulen gehören zum Medium und legen keine neue Fassung an. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
12f12117dd
commit
af85a94cd5
28 files changed
+1002
-168
No files matched your search
@@ -11,25 +11,63 @@
|
||||
|
||||
class ContentPreviewController extends Controller
|
||||
{
|
||||
public function __invoke(ContentElementVersion $version): View|StreamedResponse
|
||||
public function show(ContentElementVersion $version): View
|
||||
{
|
||||
$this->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,
|
||||
);
|
||||
|
||||
$version->loadMissing('element');
|
||||
$file = $version->metadata['file'] ?? null;
|
||||
|
||||
if (is_string($file) && $file !== '' && ! str_contains($file, '..') && Storage::disk('media_derived')->exists($file)) {
|
||||
return Storage::disk('media_derived')->response($file, basename($file), [
|
||||
'Content-Disposition' => 'inline',
|
||||
]);
|
||||
}
|
||||
|
||||
return view('content.preview', [
|
||||
'version' => $version,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user