import type { Metadata } from "next"; import { cookies } from "next/headers"; import { authCookieHeader } from "@/lib/cookies"; import { fetchAdminUserAudit, fetchAdminUserAuditPosts, type AdminAuditPostItem, } from "@/lib/api"; import { getMeCached } from "@/lib/serverData"; import { isOwner, isSuperOrOwner } from "@/lib/roles"; import Forbidden from "../../Forbidden"; import UserAuditClient from "./UserAuditClient"; export const metadata: Metadata = { title: "用户内容档案", }; interface PageProps { params: Promise<{ id: string }>; } export default async function AdminUserAuditPage({ params }: PageProps) { const { id: idRaw } = await params; const userId = parseInt(idRaw, 10); if (!Number.isFinite(userId) || userId <= 0) { return ; } const cookie = authCookieHeader(await cookies()); const me = await getMeCached(cookie || undefined); if (!me.user || !isSuperOrOwner(me.user.role)) { return ; } if (!isOwner(me.user.role)) { return ; } const cookieOrUndef = cookie || undefined; const [profileSettled, postsSettled] = await Promise.all([ fetchAdminUserAudit(userId, cookieOrUndef) .then((profile) => ({ ok: true as const, profile })) .catch((e) => ({ ok: false as const, error: e instanceof Error ? e.message : "获取用户档案失败", })), fetchAdminUserAuditPosts(userId, 1, cookieOrUndef) .then((res) => ({ ok: true as const, res })) .catch((e) => ({ ok: false as const, error: e instanceof Error ? e.message : "获取帖子失败", })), ]); if (!profileSettled.ok) { return ; } const initialPosts: AdminAuditPostItem[] = postsSettled.ok ? postsSettled.res.items || [] : []; const initialPostsTotal = postsSettled.ok ? postsSettled.res.total : 0; const initError = postsSettled.ok ? "" : postsSettled.error; const profile = profileSettled.profile; return ( ); }