feat: 新增CWD评论系统前后端代码及文档
refactor: 移除旧版评论系统代码并重构为Vue3前端 docs: 更新后端配置文档说明 fix: 修复评论提交频率限制和邮件通知逻辑 style: 格式化代码并优化样式 test: 添加Vitest测试配置 build: 更新依赖项和构建配置 chore: 清理无用文件和缓存
This commit is contained in:
41
cwd-comments-api/src/api/admin/listComments.ts
Normal file
41
cwd-comments-api/src/api/admin/listComments.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Context } from 'hono';
|
||||
import { Bindings } from '../../bindings';
|
||||
|
||||
export const listComments = async (c: Context<{ Bindings: Bindings }>) => {
|
||||
const page = parseInt(c.req.query('page') || '1');
|
||||
const limit = 10;
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
// 1. 获取总数
|
||||
const totalCount = await c.env.CWD_DB.prepare(
|
||||
"SELECT COUNT(*) as count FROM Comment"
|
||||
).first<{ count: number }>();
|
||||
|
||||
// 2. 分页查询数据
|
||||
const { results } = await c.env.CWD_DB.prepare(
|
||||
`SELECT * FROM Comment ORDER BY pub_date DESC LIMIT ? OFFSET ?`
|
||||
).bind(limit, offset).all();
|
||||
|
||||
// 3. 映射字段名以符合你的 API 规范
|
||||
const data = results.map((row: any) => ({
|
||||
id: row.id,
|
||||
pubDate: row.pub_date,
|
||||
author: row.author,
|
||||
email: row.email,
|
||||
postSlug: row.post_slug,
|
||||
url: row.url,
|
||||
ipAddress: row.ip_address,
|
||||
contentText: row.content_text,
|
||||
contentHtml: row.content_html,
|
||||
status: row.status
|
||||
}));
|
||||
|
||||
return c.json({
|
||||
data,
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
total: Math.ceil((totalCount?. count || 0) / limit)
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user