- /geschichten — published-stories index with filter pills + "+ Neue Geschichte"
for BLOG_WRITERs; supports ?personId and ?documentId pre-filtering
- /geschichten/[id] — reader detail with sanitised {@html} body, person and
document chip sections, BLOG_WRITER edit/delete with confirm dialog
- /geschichten/new — editor with optional ?personId and ?documentId pre-fill
(silent ignore on unknown IDs to avoid leaking entity existence)
- /geschichten/[id]/edit — editor populated from existing story; BLOG_WRITE
guard redirects readers to the detail page
All routes load via createApiClient(fetch) with !response.ok error handling
following the project pattern; PATCH/DELETE go through raw fetch which the
Vite dev proxy / Caddy production proxy authenticates via cookie.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { redirect } from '@sveltejs/kit';
|
|
import { createApiClient } from '$lib/api.server';
|
|
import type { PageServerLoad } from './$types';
|
|
|
|
export const load: PageServerLoad = async ({ url, fetch, parent }) => {
|
|
const layout = await parent();
|
|
if (!layout.canBlogWrite) {
|
|
throw redirect(303, '/geschichten');
|
|
}
|
|
|
|
const api = createApiClient(fetch);
|
|
const personId = url.searchParams.get('personId');
|
|
const documentId = url.searchParams.get('documentId');
|
|
|
|
const [personResult, documentResult] = await Promise.all([
|
|
personId
|
|
? api.GET('/api/persons/{id}', { params: { path: { id: personId } } })
|
|
: Promise.resolve(null),
|
|
documentId
|
|
? api.GET('/api/documents/{id}', { params: { path: { id: documentId } } })
|
|
: Promise.resolve(null)
|
|
]);
|
|
|
|
// Silently ignore 404/403 to avoid leaking entity existence on unknown IDs.
|
|
const initialPersons =
|
|
personResult && personResult.response.ok && personResult.data ? [personResult.data] : [];
|
|
const initialDocuments =
|
|
documentResult && documentResult.response.ok && documentResult.data
|
|
? [documentResult.data]
|
|
: [];
|
|
|
|
return { initialPersons, initialDocuments };
|
|
};
|