feat: 改进评论系统管理员识别与样式展示
- 后端评论接口增加 isAdmin 字段,不再依赖前端邮箱比对 - 管理后台评论列表支持 Markdown 渲染并添加相应样式 - 前端组件移除 adminEmail 依赖,改用 comment.isAdmin 字段 - 添加 CSS 样式兼容其他框架导入的表情元素 - 更新文档说明部署流程
This commit is contained in:
@@ -52,12 +52,25 @@ export const getComments = async (c: Context<{ Bindings: Bindings }>) => {
|
||||
ORDER BY priority DESC, created DESC
|
||||
`
|
||||
}
|
||||
const { results } = await c.env.CWD_DB.prepare(query).bind(...slugList).all()
|
||||
|
||||
// 并行获取评论和管理员邮箱
|
||||
// 对 adminEmail 查询进行错误捕获,防止因 Settings 表不存在导致整个接口失败
|
||||
const [commentsResult, adminEmailRow] = await Promise.all([
|
||||
c.env.CWD_DB.prepare(query).bind(...slugList).all(),
|
||||
c.env.CWD_DB.prepare('SELECT value FROM Settings WHERE key = ?')
|
||||
.bind('admin_notify_email')
|
||||
.first<{ value: string }>()
|
||||
.catch(() => null)
|
||||
]);
|
||||
|
||||
const results = commentsResult.results;
|
||||
const adminEmail = adminEmailRow?.value || null;
|
||||
|
||||
// 2. 批量处理头像并格式化
|
||||
const allComments = await Promise.all(results.map(async (row: any) => ({
|
||||
...row,
|
||||
avatar: await getCravatar(row.email, avatar_prefix || undefined),
|
||||
isAdmin: adminEmail && row.email === adminEmail,
|
||||
replies: []
|
||||
})))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user