feat(comments): 匿名评论升级为「悄悄话」——只藏内容不藏身份;fix: PJAX 瞬断自动重试

- 悄悄话:头像/昵称/头衔/等级/IP归属照常显示,仅内容对非管理员请求剥空
  (F12/网络面板拿不到原文),博主后台/登录态/邮件看全文
- 开关挪进底栏 .atk-bottom-left、表情/预览按钮右边,移动端不挤;
  回复悄悄话勾不勾随自己(去掉自动勾选)
- 前端识别:服务端剥空后 .atk-content 为空即悄悄话(空评论会被后端拒绝、
  纯表情评论有 img 不误判),无需解析 API
- 邮件页面标题书名号《》保留(按用户要求)
- PJAX 偶发「连不上服务器」:GET /api/v2 网络错误或 5xx 静默重试 2 次
  (700ms/1800ms 退避),POST 不重试,被 abort 的请求不续命
This commit is contained in:
zqlit committed 2026-10-05 10:05:21 +08:00
1 parent 8521c3f385
commit ff789a2fc9
7 files changed
+183 -60

No files matched your search

+6 -6
View File
@@ -296,6 +296,7 @@ export async function listComments(ctx: Ctx): Promise<Response> {
ipRegion: await isIPRegionEnabled(env),
visibility,
includeMarked: admin, // 只有后台要 content_marked,前台不带(省一半流量)
revealAnonymous: admin, // 管理员请求:匿名评论给真实身份和内容
});
const resp: Record<string, unknown> = { comments, count, roots_count: rootsCount };
@@ -489,6 +490,7 @@ export async function createComment(ctx: Ctx): Promise<Response> {
const [cooked] = await cookComments(env, [row], {
ipRegion: await isIPRegionEnabled(env),
includeMarked: !!author.is_admin,
revealAnonymous: !!author.is_admin,
});
// 通知(站内):回复时给父评论作者写一条
@@ -510,9 +512,7 @@ export async function createComment(ctx: Ctx): Promise<Response> {
const siteUrl = await siteFirstUrl(env, siteName);
await notifyByEmail(env, {
newComment: row,
// 匿名评论:邮件里的昵称也用「匿名」——收件人可能是任何第三方,
// 真实昵称不能从邮件漏出去(邮箱本来就是只进不出)
author: anonymous ? { ...author, name: '匿名' } : author,
author,
parent,
parentAuthor,
siteName,
@@ -542,12 +542,12 @@ export async function getComment(ctx: Ctx): Promise<Response> {
const admin = await isAdminRequest(ctx.env, ctx.req, ctx.user);
if (row.is_pending && !admin) return fail(404, 'Comment not found');
const [cooked] = await cookComments(ctx.env, [row], { includeMarked: admin });
const [cooked] = await cookComments(ctx.env, [row], { includeMarked: admin, revealAnonymous: admin });
let reply: CookedComment | undefined;
if (row.rid) {
const parentRow = await findComment(ctx.env, row.rid);
if (parentRow) {
[reply] = await cookComments(ctx.env, [parentRow], { includeMarked: admin });
[reply] = await cookComments(ctx.env, [parentRow], { includeMarked: admin, revealAnonymous: admin });
}
}
return ok({ comment: cooked, reply_comment: reply });
@@ -606,7 +606,7 @@ export async function updateComment(ctx: Ctx): Promise<Response> {
}
const updated = await findComment(env, id);
const [cooked] = await cookComments(env, updated ? [updated] : [], { includeMarked: admin });
const [cooked] = await cookComments(env, updated ? [updated] : [], { includeMarked: admin, revealAnonymous: admin });
return ok(cooked ?? {});
}