feat(评论): 添加评论置顶功能

- 在评论表中添加 priority 字段用于控制置顶权重
- 修改所有评论查询接口按 priority 和 created 排序
- 在管理后台添加置顶权重编辑功能
- 在评论列表显示置顶标识
This commit is contained in:
anghunk
2026-01-21 21:25:08 +08:00
parent 47c2eed6b5
commit 3871620fed
7 changed files with 51 additions and 16 deletions

View File

@@ -13,14 +13,13 @@ export const getComments = async (c: Context<{ Bindings: Bindings }>) => {
if (!post_slug) return c.json({ message: "post_slug is required" }, 400)
try {
// 1. 查询审核通过的评论
const query = `
SELECT id, name, email, url, content_text as contentText,
content_html as contentHtml, created, parent_id as parentId,
post_slug as postSlug
post_slug as postSlug, priority
FROM Comment
WHERE post_slug = ? AND status = "approved"
ORDER BY created DESC
ORDER BY priority DESC, created DESC
`
const { results } = await c.env.CWD_DB.prepare(query).bind(post_slug).all()
@@ -105,4 +104,4 @@ export const getComments = async (c: Context<{ Bindings: Bindings }>) => {
} catch (e: any) {
return c.json({ message: e.message }, 500)
}
}
}