mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 19:51:17 +00:00
39 lines
1.7 KiB
TypeScript
39 lines
1.7 KiB
TypeScript
import type { Metadata } from "next"
|
|
import { notFound, redirect } from "next/navigation"
|
|
import { verifySession } from "@/lib/supabase/dal"
|
|
import { resolveContent } from "@/modules/templates/lib/content"
|
|
import { getTemplate } from "@/modules/templates/lib/registry"
|
|
import { getVariant } from "@/modules/templates/queries/variants"
|
|
import { LivePreview } from "@/modules/templates/ui/components/live-preview"
|
|
import { TemplateRenderer } from "@/modules/templates/ui/components/template-renderer"
|
|
|
|
export const metadata: Metadata = {
|
|
title: "Vorschau",
|
|
robots: { index: false, follow: false },
|
|
}
|
|
|
|
// Interne Vorschau für Admins: Grundvorlage, gespeicherte Variante (?variant=) oder Live-Modus für den Editor (?live=1)
|
|
export default async function TemplatePreviewPage({ params, searchParams }: PageProps<"/preview/[key]">) {
|
|
const session = await verifySession()
|
|
if (!session.isAdmin) redirect("/client/dashboard")
|
|
|
|
const { key } = await params
|
|
const { variant: variantId, live } = await searchParams
|
|
const def = getTemplate(key)
|
|
if (!def) notFound()
|
|
|
|
let raw: unknown = {}
|
|
if (typeof variantId === "string") {
|
|
const variant = await getVariant(variantId)
|
|
if (!variant || variant.template_key !== def.key) notFound()
|
|
raw = variant.content
|
|
}
|
|
|
|
const content = resolveContent(def, raw)
|
|
// KI-Chat und -Demos brauchen eine gespeicherte Variante als Wissensquelle
|
|
const access = typeof variantId === "string" ? { variantId } : null
|
|
|
|
return live === "1"
|
|
? <LivePreview templateKey={def.key} initialContent={content} access={access} />
|
|
: <TemplateRenderer templateKey={def.key} content={content} access={access} />
|
|
}
|