Skip to content

API 接口参考 ​

默认服务地址为 http://localhost:6689。项目没有统一的 /api 全局前缀:实时热榜使用 /hot-lists,历史、调度和简报接口使用 /api/*。

健康检查 ​

方法路径说明
GET/服务首页
GET/health进程、内存和 Redis 健康状态
GET/readyMongoDB 已连接时返回 200,否则返回 503
bash
curl http://localhost:6689/health
curl http://localhost:6689/ready

Redis 不可用时可能返回 status: "degraded"。

实时热榜 ​

方法路径说明
GET/hot-lists/all获取所有已注册来源
GET/hot-lists/:source获取指定来源热榜

通用查询参数:

参数类型必填说明
limitnumber否限制返回条数
noCacheboolean否是否尝试绕过缓存
rssboolean否是否返回 RSS XML
typestring否部分来源支持的榜单类别
bash
curl 'http://localhost:6689/hot-lists/zhihu?limit=10&noCache=false'

详细说明见获取热榜。

历史热点 ​

方法路径说明
GET/api/history/search搜索和分页查询历史热点
GET/api/history/sources获取已保存的数据源列表
GET/api/history/stats获取热点数据统计
GET/api/history/configs获取来源抓取配置
GET/api/history/latest获取最新历史热点
GET/api/history/range/:source/:startTime/:endTime按 Unix 毫秒时间戳范围查询

GET /api/history/search 查询参数:

参数类型默认值说明
sourcestring全部来源 ID
keywordstring无标题和描述的字面量关键词,最多 100 字符
startDatedate无开始日期,ISO 日期字符串
endDatedate无结束日期,ISO 日期字符串
pagenumber1页码,最小为 1
limitnumber20每页条数,范围 1–100
sortBystringtimestamptimestamp、title 或 createdAt
sortOrderstringdescasc 或 desc
bash
curl 'http://localhost:6689/api/history/search?source=zhihu&keyword=AI&page=1&limit=10'

详细说明见历史热点。

GET /api/history/latest 的 limit 默认 50,范围 1–100;/api/history/stats 在进程内缓存最多 30 秒。

热点抓取调度器 ​

方法路径说明
GET/api/scheduler/status获取运行状态
GET/api/scheduler/runs/:runId查询手动抓取进度和结果,进程内保留最多一小时
GET/api/scheduler/ignored-sources获取不保存的来源
GET/api/scheduler/configs获取全部来源配置
POST/api/scheduler/start启动调度器
POST/api/scheduler/stop停止调度器
POST/api/scheduler/trigger立即抓取全部或指定来源
POST/api/scheduler/reconfigure根据当前配置重新注册 Cron
PUT/api/scheduler/config/:source更新来源的启用状态或抓取间隔

立即抓取单个来源:

bash
curl -X POST http://localhost:6689/api/scheduler/trigger \
  -H 'Content-Type: application/json' \
  -d '{"source":"zhihu"}'

此请求返回 202,响应中的 runId 可用于查询任务结果。

更新来源配置:

bash
curl -X PUT http://localhost:6689/api/scheduler/config/zhihu \
  -H 'Content-Type: application/json' \
  -d '{"enabled":true,"interval":30}'

AI 每日简报 ​

方法路径说明
POST/api/briefs/generate手动生成简报
GET/api/briefs/config获取非敏感简报配置
GET/api/briefs/latest获取最新成功简报
GET/api/briefs分页查询简报
GET/api/briefs/statistics/stocks获取历史股票出现次数排名
GET/api/briefs/:date获取指定日期简报
DELETE/api/briefs/:date删除指定日期简报
DELETE/api/briefs/history按日期或保留周期批量清理
GET/api/briefs/scheduler/status获取简报调度状态
POST/api/briefs/scheduler/start启动简报调度器
POST/api/briefs/scheduler/stop停止简报调度器
POST/api/briefs/scheduler/reconfigure重新注册简报 Cron

生成测试简报:

bash
curl -X POST http://localhost:6689/api/briefs/generate \
  -H 'Content-Type: application/json' \
  -d '{"sources":["cls"],"period":"manual-test","force":true}'

调试字段

includeDebug=true 会返回体积较大的 rawInputItems 和 searchEvidence,只应在后端排查时使用,常规前端请求不要携带。

删除接口

DELETE 路由会直接删除 MongoDB 记录。执行前先通过查询接口确认日期和 period,并优先用 1900-01-01 做 deletedCount: 0 的安全检查。

每日简报的请求参数、响应字段和清理规则见AI 每日简报。

校验与错误 ​

服务启用了全局请求校验:

  • 查询参数会根据 DTO 做类型转换。
  • 未声明字段通常会被移除或拒绝。
  • forbidNonWhitelisted 已启用,DTO 不接受的请求体字段会得到 400 Bad Request。
  • 不存在的热榜来源返回 404 Not Found。
  • 单个上游热榜抓取失败时,实时热榜接口可能返回 200、空数组和 message,调用方应检查响应内容。

仅供技术研究与开发测试使用