后台可注入全站 CSS/JS(SSR 生效,CSS 可热换);发帖/编辑改为锁一屏工作室;经济看板增加存量健康度;主题令牌与弹层误关一并收紧。 Co-authored-by: Cursor <cursoragent@cursor.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { cookies } from "next/headers";
|
|
import { notFound, redirect } from "next/navigation";
|
|
import { authCookieHeader } from "@/lib/cookies";
|
|
import { getMeCached } from "@/lib/serverData";
|
|
import { fetchPostDetail } from "@/lib/api";
|
|
import { canModerateBoard } from "@/lib/roles";
|
|
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) {
|
|
redirect(`/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}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|