用户档案、用户列表、内容筛选与公告页等数据到达后再换视图,避免滚动条闪动。 Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
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 <Forbidden text="无效的用户 ID。" />;
|
|
}
|
|
|
|
const cookie = authCookieHeader(await cookies());
|
|
const me = await getMeCached(cookie || undefined);
|
|
|
|
if (!me.user || !isSuperOrOwner(me.user.role)) {
|
|
return <Forbidden text="用户与角色权限仅超级管理员和站长可操作。" />;
|
|
}
|
|
if (!isOwner(me.user.role)) {
|
|
return <Forbidden text="用户内容档案仅站长可查看。" />;
|
|
}
|
|
|
|
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 <Forbidden text={profileSettled.error} />;
|
|
}
|
|
|
|
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 (
|
|
<UserAuditClient
|
|
userId={userId}
|
|
initial={profile}
|
|
initialPosts={initialPosts}
|
|
initialPostsTotal={initialPostsTotal}
|
|
initError={initError}
|
|
/>
|
|
);
|
|
}
|