Files
cwd/docs/api/public/like/get-like-status.md
anghunk 0b28c9fa4c docs: 更新API文档结构并完善功能说明
- 重构API文档侧边栏,将公开API拆分为子分类(评论、点赞、配置、身份验证、访问统计)
- 新增详细的公开API接口文档,包括评论管理、点赞功能、配置获取、身份验证和访问统计
- 完善数据统计功能文档,增加概览数据、访问明细和数据分析说明
- 更新功能设置文档,补充图片预览和个性化设置说明
- 修正管理员登录文档中的错误描述和格式问题
2026-02-06 17:55:31 +08:00

68 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 获取点赞状态
```
GET /api/like
```
获取当前页面的点赞状态和总点赞数,一般由前端组件在页面加载时自动调用。
- 方法:`GET`
- 路径:`/api/like`
- 鉴权:不需要
**查询参数**
| 名称 | 位置 | 类型 | 必填 | 说明 |
| ----------- | ----- | ------ | ---- | --------------------------------------------------- |
| `post_slug` | query | string | 是 | 页面唯一标识符,`window.location.origin + window.location.pathname` |
**请求头(可选)**
| 名称 | 必填 | 示例 | 说明 |
| ----------------- | ---- | ----------------------------- | ------------------------------ |
| `X-CWD-Like-User` | 否 | `550e8400-e29b-41d4-a716...` | 前端生成的匿名用户标识,用于区分不同用户 |
未显式传入 `X-CWD-Like-User` 时,服务端会尝试使用 `cf-connecting-ip` 作为用户标识,找不到时退回到 `anonymous`
**成功响应**
- 状态码:`200`
```json
{
"liked": false,
"alreadyLiked": false,
"totalLikes": 12
}
```
字段说明:
| 字段名 | 类型 | 说明 |
| ------------- | ------- | ---------------------------------------- |
| `liked` | boolean | 当前用户是否已点赞 |
| `alreadyLiked` | boolean | 预留字段,当前实现始终为 `false` |
| `totalLikes` | number | 当前页面的总点赞数 |
**错误响应**
- 缺少 `post_slug`
- 状态码:`400`
```json
{
"message": "post_slug is required"
}
```
- 服务器内部错误:
- 状态码:`500`
```json
{
"message": "获取点赞状态失败"
}
```