Base: http://fnp.xblog.cc:4000 | 81篇文章 | 16端点 | 2026-08-07

1. GET /api/stats

curl http://fnp.xblog.cc:4000/api/stats
→ {"totalArticles":81,"dbArticles":81,"apiVersion":"2.2"}

2. GET /api/tags

curl http://fnp.xblog.cc:4000/api/tags
→ [{"id":1,"name":"新闻"},{"id":2,"name":"游戏"},{"id":3,"name":"学习"},
   {"id":4,"name":"体育"},{"id":5,"name":"科技"},{"id":6,"name":"教程"},
   {"id":7,"name":"资源"},{"id":8,"name":"其他"}]

3. GET /api/articles

全部文章(不传参) | 分页 ?page=1&limit=20 | 搜索 ?q=关键词 | 标签 ?tag=5

curl "http://fnp.xblog.cc:4000/api/articles?limit=2"
→ {"total":81,"items":[{
  "id":151,"title":"建议在博客创建闲报官方社区","filename":"...20260806.html",
  "date":"2026-08-06","views":26,"author":"敖龘","author_id":4,
  "url":"/xb/...","thumb":"https://fnp.xblog.cc/xb/liteimg/..._thumb.jpg"
},...]}

4-6. 推荐接口

GET /api/articles/hot?limit=4    → {"section":"hot","count":4,"items":[...]}
GET /api/articles/latest?limit=4 → {"section":"latest","count":4,"items":[...]}
GET /api/articles/random?limit=4 → {"section":"random","count":4,"items":[...]}

7. GET /api/article/:id

返回完整JSON。:id支持数字ID或文件名。浏览数+1。

curl http://fnp.xblog.cc:4000/api/article/73
→ {
  "id":73,"title":"Deepseek神奇回答","filename":"...20250502.html",
  "views":942,"likes":338,"comments":7,
  "tags":[{"id":8,"name":"其他"}],
  "cover":"https://fnp.xblog.cc/xb/liteimg/Deepseek神奇回答_20250502_thumb.jpg",
  "body":"<figure><img src=\"...\"></figure><p>正文</p>",
  "date":"2025-05-02",
  "author":{"id":6,"username":"闲报","role":"admin"}
}

body为HTML富文本,客户端用WebView渲染。

8. GET /api/article/:id/info

同article但body→summary(200字纯文本)。

curl http://fnp.xblog.cc:4000/api/article/3/info
→ {"id":3,"title":"系统功能测试","views":576,"likes":77,"comments":5,
   "tags":[{"id":5,"name":"科技"},{"id":8,"name":"其他"}],
   "summary":"测试 测试 测试...","cover":"https://...liteimg/..._thumb.jpg",
   "author":{"id":3,"username":"测试用户","role":"user","bio":""}}

9. GET /api/author/:id

curl http://fnp.xblog.cc:4000/api/author/6
→ {"author":{"id":6,"username":"闲报","role":"admin","bio":"官方账号"},
   "stats":{"total_articles":60},
   "articles":[{"id":151,"title":"...","url":"/xb/...","views":7,"date":"2026-08-06"}]}

10. GET /api/comments

curl "http://fnp.xblog.cc:4000/api/comments?article_id=3"
→ [{"id":89,"name":"游客001","content":"API游客评论测试",
    "time":"2026-08-05T03:25:07.000Z","likes":0,"user":null},
   {"id":4,"name":"测试用户","content":"测试用户评论功能",
    "time":"2026-04-06T13:46:38.000Z","likes":39,
    "user":{"id":3,"username":"测试用户","role":"user"}}]

11. POST /api/like

点赞(免登录,IP去重)。

curl -X POST .../api/like -H 'Content-Type: application/json' \
  -d '{"article_id":150}'
→ {"ok":true}

点赞评论:
curl -X POST .../api/like -H 'Content-Type: application/json' \
  -d '{"article_id":150,"comment_id":5}'
→ {"ok":true}

12. POST /api/comment

评论(免登录,违禁词过滤)。

curl -X POST .../api/comment -H 'Content-Type: application/json' \
  -d '{"article_id":150,"content":"好文章"}'
→ {"id":91,"ok":true}

游客传name:
curl ... -d '{"article_id":150,"content":"好","name":"游客昵称"}'
→ {"id":92,"ok":true}

违禁词拦截:
→ {"error":"内容包含违禁词「广告」"} (400)

13. POST /api/login

curl -X POST .../api/login -H 'Content-Type: application/json' \
  -d '{"username":"闲报","password":"admin123"}'
→ {"token":"abc123def...","user":{"id":6,"username":"闲报","role":"admin","bio":"官方账号"}}

Token有效期24h。Header: Authorization: Bearer <token>

14. POST /api/register

curl -X POST .../api/register -H 'Content-Type: application/json' \
  -d '{"username":"新用户","email":"new@test.com","password":"123456"}'
→ 201 {"token":"def456...","user":{"id":10,"username":"新用户","role":"user","bio":""}}
违禁词: → {"error":"昵称包含违禁词「广告」"} (400)

15. GET /api/me

curl .../api/me -H 'Authorization: Bearer <token>'
→ {"user":{"id":6,"username":"闲报","email":"xblog@qq.com","role":"admin","bio":"官方账号"},
   "stats":{"total":60,"published":60,"pending":0},
   "articles":[{"id":151,"title":"...","url":"/xb/...","views":7,"status":"已发布","date":"2026-08-06"}]}

16. POST /api/me/bio

curl -X POST .../api/me/bio -H 'Authorization: Bearer <token>' \
  -d '{"bio":"新的个性留言"}'
→ {"ok":true,"bio":"新的个性留言"}
违禁词: → {"error":"留言包含违禁词「广告」"} (400)

数据库

记录
articles81
tags8
article_tags91
comments89
likes6827
users10

闲报开发组 2026-08-07