import Link from "next/link"; import { CodeXml, Lock, Copy, Eye, MessageSquare, GitFork } from "lucide-react"; import { fetchSnippetById } from "@/lib/api"; import { postViewerCookieHeader } from "@/lib/cookies"; import { getPublicSettingsCached } from "@/lib/serverData"; import { cookies } from "next/headers"; import { snippetPath } from "@/lib/urlStyle"; import Avatar from "@/components/Avatar"; /** * [snippet id=N] 嵌入卡片(SSR)。 * 私有/已删除/不存在时渲染降级占位,不暴露内容。 */ export default async function MdSnippet({ id }: { id: number }) { const cookieHeader = postViewerCookieHeader(await cookies()); const [data, settings] = await Promise.all([ fetchSnippetById(id, cookieHeader).catch(() => null), getPublicSettingsCached(), ]); const urlStyle = settings.url_style; // 降级占位:不存在 / 私有且无权限 / 已删除 if (!data) { return (
代码片段 #{id}
片段不存在或无权查看
{s.title}
{previewLines.map((line, i) => (
{i + 1}
{line || " "}
))}