> ## 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}
POST /api/posts/:id/stats
```

**请求体：**

```json theme={null}
{
  "action": "view"
}
```

| action | 说明    |
| ------ | ----- |
| `view` | 阅读 +1 |
| `like` | 点赞 +1 |

**响应：**

```json theme={null}
{
  "ok": true,
  "views": 100,
  "likes": 25
}
```

<Info>
  点赞频控：每 IP 每分钟最多 10 次。
</Info>

## 30 天趋势数据

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

**响应：**

```json theme={null}
{
  "ok": true,
  "trend": [
    { "date": "2025-01-01", "views": 150, "likes": 12 },
    { "date": "2025-01-02", "views": 200, "likes": 18 }
  ]
}
```

## 数据存储

### stats 表

| 字段        | 类型        | 说明        |
| --------- | --------- | --------- |
| `post_id` | `TEXT`    | 文章 ID（主键） |
| `likes`   | `INTEGER` | 累计点赞      |
| `views`   | `INTEGER` | 累计阅读      |

### stats\_daily 表

按 `(post_id, date)` 累加每日聚合数据。

## 静态模式

数据存储在 `localStorage`：`blog_views_{postId}`、`blog_likes_{postId}`，仅限本机。
