统一投票/悬赏/抽奖截止与状态展示,抽奖支持多奖品行;发帖页悬赏积分对齐表格输入,并在余额不足时于底部就地提示。 Co-authored-by: Cursor <cursoragent@cursor.com>
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import { cookies } from "next/headers";
|
|
import { notFound, redirect } from "next/navigation";
|
|
import Link from "next/link";
|
|
import { ChevronRight } from "lucide-react";
|
|
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
|
|
data-compose-viewport
|
|
className="j13-compose-page w-full max-w-6xl mx-auto"
|
|
>
|
|
<nav className="meta mb-4 flex items-center gap-1.5 flex-wrap text-[13px] shrink-0">
|
|
<Link href="/" className="hover:text-[var(--accent)] transition-colors">
|
|
首页
|
|
</Link>
|
|
<ChevronRight size={13} />
|
|
<Link
|
|
href={`/post/${post.id}`}
|
|
className="hover:text-[var(--accent)] transition-colors truncate max-w-[12rem]"
|
|
>
|
|
帖子详情
|
|
</Link>
|
|
<ChevronRight size={13} />
|
|
<span style={{ color: "var(--ink-2)" }}>编辑</span>
|
|
</nav>
|
|
|
|
<EditPostClient
|
|
postId={post.id}
|
|
initialTitle={post.title}
|
|
initialContent={post.content}
|
|
initialTags={post.tags || ""}
|
|
initialPostType={post.post_type}
|
|
initialContentAccess={post.content_access}
|
|
initialAccessPoints={post.access_points}
|
|
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>
|
|
);
|
|
}
|