36 lines
1.5 KiB
TypeScript
36 lines
1.5 KiB
TypeScript
import { notFound } from "next/navigation";
|
||
|
||
import { BackendDownNotice } from "@/components/BackendDownNotice";
|
||
import { OutlineEditor } from "@/components/outline/OutlineEditor";
|
||
import { fetchOutline, fetchProject } from "@/lib/api/server";
|
||
import type { ProjectResponse } from "@/lib/api/types";
|
||
|
||
interface PageProps {
|
||
params: Promise<{ id: string }>;
|
||
}
|
||
|
||
// 大纲编辑器页(UX §6.7)。Server Component 取项目 + 已存大纲(GET .../outline,
|
||
// 空/错误降级为空列表)作为初始章节,重访时显已生成的大纲;OutlineEditor(Client)
|
||
// 仍按需触发 POST .../outline 生成/覆盖所显章节。
|
||
export default async function OutlinePage({ params }: PageProps) {
|
||
const { id } = await params;
|
||
|
||
// 仅当项目确实不存在(404)才判 notFound;后端不可用等其它失败降级为「后端不可达」提示,
|
||
// 不把整页变成「找不到页面」。次级拉取(大纲)的瞬时错误已在 fetchOutline 内降级为空。
|
||
let project: ProjectResponse;
|
||
try {
|
||
project = await fetchProject(id);
|
||
} catch (err) {
|
||
if (isNotFoundError(err)) notFound();
|
||
return <BackendDownNotice className="m-6" />;
|
||
}
|
||
|
||
const initialChapters = await fetchOutline(id);
|
||
return <OutlineEditor project={project} initialChapters={initialChapters} />;
|
||
}
|
||
|
||
// fetchProject 抛错信息形如「请求失败 404: ...」;据此区分「项目不存在」与「后端不可用」。
|
||
function isNotFoundError(err: unknown): boolean {
|
||
return err instanceof Error && err.message.includes("请求失败 404");
|
||
}
|