> ## Documentation Index
> Fetch the complete documentation index at: https://docs.2024921.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# 评论

> 评论系统接口，支持嵌套回复

## 获取文章评论

```http theme={null}
GET /api/posts/:id/comments
```

**响应：**

```json theme={null}
{
  "ok": true,
  "comments": [
    {
      "id": "评论ID",
      "post_id": "文章ID",
      "author": "评论者",
      "content": "内容",
      "date": "2025-01-01T00:00:00Z",
      "status": "approved",
      "parent_id": null
    }
  ]
}
```

## 发表评论

```http theme={null}
POST /api/posts/:id/comments
```

**请求体：**

```json theme={null}
{
  "author": "评论者名称",
  "content": "评论内容",
  "parentId": "父评论 ID（可选）"
}
```

<Info>
  无需认证，公开接口。有 IP 频率限制。
</Info>

## 全局评论列表（管理）

```http theme={null}
GET /api/comments
Authorization: Bearer <token>
```

**查询参数：** `status`（approved/pending/空）、`page`、`pageSize`

**响应包含 `post_title` 字段，方便管理后台展示。**

## 更新 / 删除

```http theme={null}
PUT    /api/comments/:id    # 更新状态 {"status": "approved"}
DELETE /api/comments/:id    # 删除
```

都需要认证。

## 嵌套回复

评论通过 `parent_id` 支持一级嵌套：

```
评论 A
├── 回复 A1 (parent_id: A)
└── 回复 A2 (parent_id: A)
    └── 回复 A2-1 (parent_id: A2)
```

## 安全机制

| 机制        | 说明      |
| --------- | ------- |
| XSS 防护    | 输入自动转义  |
| SQL 注入    | 参数化查询   |
| 频率限制      | 每 IP 限频 |
| Origin 校验 | 验证请求来源  |
