feat(comments): 支持编辑与管理可见历史,采纳展示改用楼层号

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-16 08:05:41 +08:00
parent d032668c66
commit 1b2b87c976
14 changed files with 716 additions and 42 deletions

View File

@@ -238,6 +238,7 @@ export interface Post {
export interface QuestionState {
solved: boolean;
accepted_comment_id: number;
accepted_floor: number;
can_accept: boolean;
can_solve: boolean;
can_reopen: boolean;
@@ -274,6 +275,7 @@ export interface PollState {
export interface BountyState {
points: number;
accepted_comment_id: number;
accepted_floor: number;
escrowed: boolean;
refunded: boolean;
expired?: boolean;
@@ -312,6 +314,9 @@ export interface Comment {
content: string;
status: string;
created_at: string;
updated_at?: string;
/** 相对创建已编辑(服务端判定) */
edited?: boolean;
user: User;
/** 软删占位 */
deleted?: boolean;
@@ -1133,6 +1138,16 @@ export async function apiDeleteComment(
return res.json();
}
/** 编辑评论(作者或版主) */
export async function apiUpdateComment(postId: string, commentId: number, content: string) {
const res = await fetchWithRefresh(`/api/posts/${postId}/comments/${commentId}`, {
method: "PUT",
headers: clientHeaders({ "Content-Type": "application/json" }),
body: JSON.stringify({ content }),
});
return res.json();
}
/** 恢复软删评论(自删作者或版主) */
export async function apiRestoreComment(postId: string, commentId: number) {
const res = await fetchWithRefresh(`/api/posts/${postId}/comments/${commentId}/restore`, {
@@ -1773,6 +1788,34 @@ export const apiAdminRestoreComment = (id: number) =>
export const apiAdminPurgeComment = (id: number) =>
contentAction(`/api/admin/content/comments/${id}/purge`, "DELETE");
export interface CommentEditHistoryItem {
id: number;
editor: {
id: number;
username: string;
nickname: string;
avatar: string;
};
old_content: string;
created_at: string;
}
/** 管理:评论编辑历史(分页;默认每页 10 条) */
export async function apiAdminCommentHistory(
commentId: number,
page = 1,
size = 10
): Promise<{ items: CommentEditHistoryItem[]; total: number; page: number; size: number }> {
const params = new URLSearchParams({ page: String(page), size: String(size) });
const res = await fetchWithRefresh(
`/api/admin/content/comments/${commentId}/history?${params}`,
{ headers: clientHeaders() }
);
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(data.error || "获取编辑历史失败");
return data;
}
export async function fetchAdminContentCounts(
cookieHeader?: string
): Promise<AdminContentCounts> {