feat: 分离文章slug与URL字段并支持slug模式匹配查询

- 新增 `post_url` 字段存储文章完整URL,`post_slug` 仅存储标识符
- 更新管理后台评论列表、编辑、统计及域名获取接口以使用新字段
- 修改公共评论查询接口,支持slug精确匹配及带`?`、`#`参数的模糊匹配
- 更新前端管理界面,在评论编辑表单中增加"评论地址"(`postUrl`)字段
- 同步更新API文档,明确字段用途及查询参数说明
This commit is contained in:
anghunk
2026-02-09 13:36:25 +08:00
parent b2fd3e72e6
commit cf1e5b5c51
10 changed files with 135 additions and 51 deletions

View File

@@ -44,7 +44,8 @@ GET /admin/comments/list
"created": 1736762400000,
"name": "张三",
"email": "zhangsan@example.com",
"postSlug": "https://your-blog.example.com/blog/hello-world",
"postSlug": "hello-world",
"postUrl": "https://your-blog.example.com/blog/hello-world",
"url": "https://zhangsan.me",
"ipAddress": "127.0.0.1",
"contentText": "很棒的文章!",
@@ -63,6 +64,25 @@ GET /admin/comments/list
}
```
返回字段说明:
| 字段名 | 类型 | 说明 |
| ----------- | ------ | -------------------------- |
| `id` | number | 评论 ID |
| `created` | number | 创建时间戳 |
| `name` | string | 评论者昵称 |
| `email` | string | 评论者邮箱 |
| `postSlug` | string | 文章 slug |
| `postUrl` | string | null) | 文章完整 URL |
| `url` | string | null) | 评论者个人主页地址 |
| `ipAddress` | string | 评论者 IP 地址 |
| `contentText` | string | 评论内容(纯文本) |
| `contentHtml` | string | 评论内容(渲染后的 HTML |
| `status` | string | 评论状态 |
| `priority` | number | 置顶权重 |
| `ua` | string | 用户代理 |
| `avatar` | string | 头像 URLGravatar |
**鉴权错误**
- 未携带 Token 或 Token 失效:
@@ -156,7 +176,8 @@ PUT /admin/comments/update
"name": "张三",
"email": "zhangsan@example.com",
"url": "https://zhangsan.me",
"postSlug": "https://example.com/blog/hello-world",
"postSlug": "hello-world",
"postUrl": "https://example.com/blog/hello-world",
"contentText": "更新后的评论内容",
"status": "approved",
"priority": 2
@@ -171,10 +192,12 @@ PUT /admin/comments/update
| `name` | string | 是 | 评论者昵称 |
| `email` | string | 是 | 评论者邮箱 |
| `url` | string | 否 | 评论者个人主页或站点地址 |
| `postSlug` | string | 否 | 评论地址(文章 URL不传则保持原值 |
| `contentText` | string | | 评论内容(纯文本) |
`| `status` | string | | 评论状态,可选 `approved``pending``rejected` |
| `priority` | number | | 置顶权重,默认为 1数值越大越靠前 |
| `postSlug` | string | 否 | 文章 slug不传则保持原值支持 `postSlug` 或 `post_slug` |
| `postUrl` | string | | 文章完整 URL不传则保持原值支持 `postUrl` 或 `post_url` |
| `content` | string | 是* | 评论内容Markdown 或纯文本),与 `contentText` 二选一 |
| `contentText` | string | 是* | 评论内容(纯文本),与 `content` 二选一 |
| `status` | string | 否 | 评论状态,可选 `approved`、`pending`、`rejected` |
| `priority` | number | 否 | 置顶权重,默认为 1数值越大越靠前必须 >= 1 |
**置顶权重说明**

View File

@@ -16,12 +16,12 @@ GET /api/comments
**查询参数**
| 名称 | 位置 | 类型 | 必填 | 说明 |
| ----------- | ----- | ------- | ---- | -------------------------------------------------------------------------------------------- |
| `post_slug` | query | string | 是 | 使用 `window.location.origin + window`location.pathname`,获取带域名的链接,否则后台无法识别 |
| `page` | query | integer | 否 | 页码,默认 `1` |
| `limit` | query | integer | 否 | 每页数量,默认 `20`,最大 `50` |
| `nested` | query | string | 否 | 是否返回嵌套结构,默认 `'true'` |
| 名称 | 位置 | 类型 | 必填 | 说明 |
| ----------- | ----- | ------- | ---- | ------------------------------------------ |
| `post_slug` | query | string | 是 | 文章 slug与前端 `CWDComments``postSlug` 参数对应 |
| `page` | query | integer | 否 | 页码,默认 `1` |
| `limit` | query | integer | 否 | 每页数量,默认 `20`,最大 `50` |
| `nested` | query | string | 否 | 是否返回嵌套结构,默认 `'true'` |
**成功响应**
@@ -70,6 +70,25 @@ GET /api/comments
}
```
返回字段说明:
| 字段名 | 类型 | 说明 |
| ----------- | ------ | -------------------------- |
| `id` | number | 评论 ID |
| `author` | string | 评论者昵称 |
| `email` | string | 评论者邮箱hash后 |
| `url` | string | null) | 评论者个人主页地址 |
| `contentText` | string | 评论内容(纯文本) |
| `contentHtml` | string | 评论内容(渲染后的 HTML |
| `pubDate` | string | 发布时间ISO 8601 格式) |
| `postSlug` | string | 文章 slug |
| `avatar` | string | 头像 URLGravatar |
| `priority` | number | 置顶权重,数值越大排序越靠前 |
| `likes` | number | 点赞数,默认为 0 |
| `replies` | array | 子评论列表(嵌套结构时) |
| `parentId` | number | null) | 父评论 ID回复时 |
| `replyToAuthor` | string( | null) | 被回复者的昵称(回复时) |
说明:
-`nested=true`(默认)时,接口返回的是"根评论列表",每条根评论包含其 `replies`
@@ -121,7 +140,7 @@ POST /api/comments
```json
{
"post_slug": "https://example.com/blog/hello-world",
"post_slug": "hello-world",
"post_title": "博客标题,可选",
"post_url": "https://example.com/blog/hello-world",
"name": "张三",
@@ -135,16 +154,16 @@ POST /api/comments
字段说明:
| 字段名 | 类型 | 必填 | 说明 |
| ------------ | ------ | ---- | ------------------------------------------------------------------------------------------------------------- |
| `post_slug` | string | 是 | 文章唯一标识符,应与前端组件初始化时的 `postSlug` 值一致,`window.location.origin + window.location.pathname` |
| `post_title` | string | 否 | 文章标题,用于邮件通知内容 |
| `post_url` | string | 否 | 文章 URL用于邮件通知中的跳转链接 |
| `name` | string | 是 | 评论者昵称 |
| `email` | string | 是 | 评论者邮箱,需为合法邮箱格式 |
| `url` | string | 否 | 评论者个人主页或站点地址 |
| `content` | string | 是 | 评论内容,内部会过滤 `<script>...</script>` 片段 |
| `parent_id` | number | 否 | 父评论 ID用于回复功能缺省或 `null` 表示根评论 |
| 字段名 | 类型 | 必填 | 说明 |
| ------------ | ------ | ---- | -------------------------------------------------------------------- |
| `post_slug` | string | 是 | 文章 slug,应与前端组件初始化时的 `postSlug` 值一致,如 `hello-world` |
| `post_title` | string | 否 | 文章标题,用于邮件通知内容 |
| `post_url` | string | 否 | 文章完整 URL用于邮件通知中的跳转链接 |
| `name` | string | 是 | 评论者昵称 |
| `email` | string | | 是 | 评论者邮箱,需为合法邮箱格式 |
| `url` | string | 否 | 评论者个人主页或站点地址 |
| `content` | string | 是 | 评论内容,内部会过滤 `<script>...</script>` 片段 |
| `parent_id` | number | 否 | 父评论 ID用于回复功能缺省或 `null` 表示根评论 |
| `adminToken` | string | 否 | 管理员评论密钥,博主发布评论时需要先通过 `/api/verify-admin` 验证密钥后将密钥传入此字段,评论将直接通过且不受审核设置影响 |
**成功响应**