API 参考
互动接口
加星、求复现投票与关注:POST /api/stars、/api/requests、/api/follows。
本页覆盖三个仓库与用户的互动端点,公共约定:
- 鉴权:需要 write 权限(浏览器 session 或
x-api-key)。 - Body:JSON。
- 限流:各端点 60 次/小时/账号,超限返回 429。
- 目标为仓库时,需对该仓库有读取权限,否则返回 403。
- 错误统一形态为
{"error": "中文信息"}。
加星 POST /api/stars
为仓库加星或取消加星。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| repositoryId | string | 是 | 目标仓库 ID |
| action | string | 是 | star 或 unstar |
curl -X POST https://citeark.com/api/stars \
-H "x-api-key: $CITEARK_API_KEY" \
-H "content-type: application/json" \
-d '{"repositoryId": "…", "action": "star"}'成功返回 200:
{ "starCount": 12 }求复现 POST /api/requests
为仓库投出一票“希望被复现”,或撤回投票。requestCount 是社区“希望被复现”的信号,展示在仓库页。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| repositoryId | string | 是 | 目标仓库 ID |
| action | string | 是 | request 或 withdraw |
curl -X POST https://citeark.com/api/requests \
-H "x-api-key: $CITEARK_API_KEY" \
-H "content-type: application/json" \
-d '{"repositoryId": "…", "action": "request"}'成功返回 200:
{ "requestCount": 5 }关注 POST /api/follows
关注或取消关注一个仓库或用户。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| targetType | string | 是 | repository 或 user |
| targetId | string | 是 | 最长 128。targetType 为 repository 时传仓库 ID;为 user 时传用户 slug(不是用户 ID) |
| action | string | 是 | follow 或 unfollow |
curl -X POST https://citeark.com/api/follows \
-H "x-api-key: $CITEARK_API_KEY" \
-H "content-type: application/json" \
-d '{"targetType": "repository", "targetId": "…", "action": "follow"}'成功返回 200:
{ "followerCount": 8 }关注用户时的特有错误:不能关注自己返回 400 {"error": "不能关注自己"};用户不存在返回 404 {"error": "找不到这个用户"}。