Mediathek: zentrale Bildverwaltung mit Verwendungsnachweis und Bildauswahl

- Tabellen media und media_usages, Modelle Media/MediaUsage
- App\Media\MediaLibrary (store/register/replace/delete/rebuild) und
  Registry App\Media\MediaUsages (Quellen: Seiten, Neuigkeiten inkl.
  künftiger content-Spalte, Termine, Startseiten-Kacheln), ImagePaths-Extraktor
- Alle Uploads landen in der Mediathek (Seiten-Editor direkt, übrige über
  Beobachter beim Speichern); Daten-Migration und media:rebuild übernehmen
  bestehende Bilder
- Recht media.manage, Zugang media.use für alle Redaktionsbereiche
- /redaktion/mediathek (Suche, Filter, Upload mit Fortschritt, Details,
  Eingebunden in, Ersetzen, Löschen mit Warnung, Mehrfachauswahl),
  Abschnitt in der Redaktion und Menüpunkt im Admin-Bereich
- MediaPicker (Hochladen/Mediathek) im Pagebuilder: Bildfelder und
  Galerie (Mehrfachauswahl), editor.pickMedia im provide-API
- Bild-URLs mit ?v=Änderungszeit, null bei fehlender Datei; Modelle löschen
  geteilte Bilder nicht mehr selbst

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 20:05:50 +00:00
parent 3b72b5327e
commit 694ccf6ae0
46 changed files with 3101 additions and 89 deletions

View file

@ -37,6 +37,9 @@ import BlockSettings from '@/pagebuilder/editor/BlockSettings.vue';
import EditorBlockList from '@/pagebuilder/editor/EditorBlockList.vue';
import { clone, createBlock, duplicate as duplicateBlock, locate, walk } from '@/pagebuilder/editor/tree';
import { http } from '@/lib/http';
import MediaPickerHost from '@/components/media/MediaPickerHost.vue';
import { collectImagePaths, uploadWithProgress } from '@/components/media/api';
import { useMediaPicker } from '@/components/media/useMediaPicker';
import { formatTime } from '@/lib/format';
import PublishDialog from '../components/PublishDialog.vue';
import RevisionsDialog from '../components/RevisionsDialog.vue';
@ -133,14 +136,18 @@ function containsActive(item) {
return candidates.some((block) => block.items?.includes(item) || locate(item.blocks, block.id));
}
// ——— Hochladen ———
async function uploadImage(file) {
const body = new FormData();
body.append('image', file);
return http.post(`${base}/bilder`, body);
// ——— Hochladen und Mediathek ———
// Bilder landen im Verzeichnis der Seite und zugleich in der Mediathek.
async function uploadImage(file, onProgress) {
return uploadWithProgress(`${base}/bilder`, file, { onProgress });
}
const mediaPicker = useMediaPicker({
upload: uploadImage,
contextLabel: 'Auf dieser Seite',
contextPaths: () => collectImagePaths(working.content),
});
async function uploadFile(file) {
const body = new FormData();
body.append('file', file);
@ -170,6 +177,8 @@ provide('pagebuilder:editor', {
containsActive,
uploadImage,
uploadFile,
// Bildauswahl „Aus der Mediathek“: ({ multiple?, title? }) => Promise<[{ id, path, url, alt, caption, width, height }] | null>
pickMedia: (options) => mediaPicker.pick(options),
imageUrl: (path) => `${props.uploadsUrl}/${path}`,
});
provide('pagebuilder:list', EditorBlockList);
@ -632,5 +641,6 @@ const canvasWidth = computed(() => devices.find((d) => d.key === device.value).w
<NewPageDialog v-model:open="dialogs.newPage" :parent-id="page.id" :parent-title="page.title" @before-create="save" />
</div>
<MediaPickerHost :picker="mediaPicker" />
<Toaster position="bottom-left" />
</template>

View file

@ -3,13 +3,13 @@
namespace Inhaus\Plugins\Pages\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Media\MediaLibrary;
use App\Models\Role;
use App\Models\User;
use App\Notifications\PortalNotification;
use App\Pagebuilder\Blocks;
use App\Pagebuilder\Content;
use App\Support\Audit;
use App\Support\Images;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
@ -312,14 +312,15 @@ class PageEditorController extends Controller
return response()->json(['ok' => true]);
}
public function uploadImage(Request $request, Page $page, Images $images): JsonResponse
public function uploadImage(Request $request, Page $page, MediaLibrary $library): JsonResponse
{
Gate::authorize('update', $page);
$request->validate(['image' => ['required', File::image()->types(['jpg', 'jpeg', 'png', 'webp', 'gif'])->max(15 * 1024)]]);
$path = $images->storeContentImage($request->file('image'), 'pagebuilder/pages/'.$page->id);
// Landet zugleich in der Mediathek.
$media = $library->store($request->file('image'), 'pagebuilder/pages/'.$page->id, $request->user());
return response()->json(['path' => $path, 'url' => Blocks::imageUrl($path)]);
return response()->json(['path' => $media->path, 'url' => Blocks::imageUrl($media->path), 'media' => $media->toLibraryArray()]);
}
public function uploadFile(Request $request, Page $page): JsonResponse

View file

@ -3,6 +3,8 @@
namespace Inhaus\Plugins\Pages;
use App\Editorial\Editorial;
use App\Media\ImagePaths;
use App\Media\MediaUsages;
use App\Models\User;
use App\Pagebuilder\Blocks;
use App\Pagebuilder\BlockType;
@ -88,6 +90,7 @@ class PagesPlugin extends Plugin
);
$this->registerBlocks($this->app->make(Blocks::class));
$this->registerMediaUsages($this->app->make(MediaUsages::class));
}
public function boot(): void
@ -98,6 +101,33 @@ class PagesPlugin extends Plugin
})->everyMinute()->name('pages-scheduled')->withoutOverlapping(5);
}
/**
* Mediathek „Eingebunden in“: veröffentlichter Inhalt, Entwurf und geplanter Stand.
*/
private function registerMediaUsages(MediaUsages $usages): void
{
$usages->add('pages', 'Seiten', function (Page $page) {
$entries = [];
$url = route('pages.editor', $page, false);
foreach (['content' => false, 'scheduled_content' => true, 'draft' => true] as $column => $draft) {
$title = match ($column) {
'draft' => $page->draft_title ?? $page->title,
'scheduled_content' => $page->scheduled_title ?? $page->title,
default => $page->title,
};
foreach (ImagePaths::fromContent($page->{$column}) as $context => $paths) {
$entries[] = ['context' => $context, 'label' => $title, 'url' => $url, 'draft' => $draft, 'paths' => $paths];
}
}
return $entries;
}, fn (callable $each) => Page::query()->chunkById(50, fn ($pages) => $pages->each($each)));
$usages->watch('pages', Page::class, ['content', 'draft', 'scheduled_content', 'title', 'draft_title', 'scheduled_title']);
}
private function registerBlocks(Blocks $blocks): void
{
$blocks->add(BlockType::make('downloads', 'Downloads', 'file-down', 'media', 'pages::Downloads')