28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import { notFound, redirect } from "next/navigation";
|
|
import { connection } from "next/server";
|
|
|
|
import { StructuredGuideShell } from "@/components/public/structured-guide";
|
|
import { getAdminSession } from "@/lib/auth/server";
|
|
import { publicGuideSections } from "@/lib/guides/public-sections";
|
|
import { getAdminGuideContent, getGuideEditorHeader } from "@/lib/guides/queries";
|
|
|
|
export const instant = false;
|
|
|
|
export default async function GuidePreviewPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ character: string; page?: string[] }>;
|
|
}) {
|
|
await connection();
|
|
if (!(await getAdminSession())) redirect("/admin/login");
|
|
const { character, page } = await params;
|
|
if (page && page.length > 1) notFound();
|
|
const header = await getGuideEditorHeader(character);
|
|
if (!header) notFound();
|
|
const guide = await getAdminGuideContent(header.slug);
|
|
if (!guide) notFound();
|
|
const section = page?.[0];
|
|
if (section && !publicGuideSections(guide).some((item) => item.slug === section)) notFound();
|
|
return <StructuredGuideShell guide={guide} section={section} preview />;
|
|
}
|