- 新增 urlStyle 工具与测试:postPath/userPath/sitePagePath 统一生成链接 - 管理端新增 UrlStylePanel 设置面板,settings 服务与 handler 适配 - 全站路由链接与 JSON-LD/sitemap 切换为统一 URL 生成 - middleware 与相关组件适配
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { cookies } from "next/headers";
|
|
import { notFound, redirect } from "next/navigation";
|
|
import { authCookieHeader } from "@/lib/cookies";
|
|
import { getMeCached, getPublicSettingsCached } from "@/lib/serverData";
|
|
import { fetchPostDetail } from "@/lib/api";
|
|
import { canModerateBoard } from "@/lib/roles";
|
|
import { postPath } from "@/lib/urlStyle";
|
|
import EditPostClient from "./EditPostClient";
|
|
|
|
interface PageProps {
|
|
params: Promise<{ id: string }>;
|
|
}
|
|
|
|
export default async function EditPostPage({ params }: PageProps) {
|
|
const { id } = await params;
|
|
const cookie = authCookieHeader(await cookies());
|
|
const me = await getMeCached(cookie || undefined);
|
|
if (!me.user) {
|
|
redirect(`/login?redirect=${encodeURIComponent(`/post/${id}/edit`)}`);
|
|
}
|
|
|
|
let post: Awaited<ReturnType<typeof fetchPostDetail>>["post"];
|
|
try {
|
|
({ post } = await fetchPostDetail(id, cookie));
|
|
} catch {
|
|
notFound();
|
|
}
|
|
|
|
const allowed =
|
|
me.user.id === post.user.id ||
|
|
canModerateBoard(me.user, post.board_id);
|
|
if (!allowed) {
|
|
const urlStyle = (await getPublicSettingsCached()).url_style;
|
|
redirect(postPath(urlStyle, post.id));
|
|
}
|
|
|
|
return (
|
|
<div className="j13-compose-page w-full">
|
|
<EditPostClient
|
|
postId={post.id}
|
|
initialTitle={post.title}
|
|
initialContent={post.content}
|
|
initialTags={post.tags || ""}
|
|
initialPostType={post.post_type}
|
|
initialTypeMeta={post.type_meta}
|
|
initialAttachments={post.attachments || []}
|
|
canEditPollOptions={post.poll?.can_edit_options !== false}
|
|
canEditLotteryPrizes={post.lottery?.can_edit_prizes !== false}
|
|
boardName={post.board?.name || "未知板块"}
|
|
boardId={post.board_id}
|
|
boardColorIndex={post.board?.color_index ?? 0}
|
|
boardIcon={post.board?.icon}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|