Files
buzz-sheet/app/admin/[character]/preview/[[...page]]/page.tsx
T
gunshiz 9896e8a4ad
CI / Verify (push) Successful in 1m35s
CI / Build immutable images and deploy (push) Successful in 5m27s
feat(guides) : add safer publishing and discovery
2026-09-19 13:32:57 +07:00

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 />;
}