feat(ingest): API Push 短新闻接口层

- POST /api/v1/ingest:鉴权(X-Ingest-Token) + 限速(每 token 2 篇/秒,
  Redis 滑动桶,INGEST_RATE_PER_SEC 可调) + 三层去重(L1 external_id /
  L2 content_hash / L3 DB UNIQUE 兜底,均带 reason)
- 写入字段:is_short_news=True、translation/format/image_ai_status='n/a'、
  classify_status=(有 tags?'ok':'pending')、commentary_{angel,meituan}_status='pending'、
  body_zh_text=body_text(走统一路径,前端/prompt 不用改)
- services/fetchers/api_push.py:compute_content_hash + synthesize_url +
  normalize_published_at + build_initial_status 纯函数
- schemas/ingest.py:IngestPayload(title 1-200/body 1-5000/tags 去重去空) +
  IngestResponse(article_id/content_hash/status/reason/matched_external_id)
- admin.py:POST/GET/DELETE /admin/sources/{id}/ingest-tokens — owner 生成
  (raw_token 仅一次性返回)、列出、撤销
- schemas/article.py:ArticleListItem 加 is_short_news/source_ref;
  ArticleDetail 加 is_short_news/source_ref/external_id
- main.py:挂 ingest router;config.py + .env.example:ingest_rate_per_sec 默认 2

短新闻由 commit 1 enrichment_loop 自动接管 classify + 双 provider commentary,
跳过 format/image。
This commit is contained in:
xiaji
2026-06-14 16:04:45 +08:00
parent 3091f291b2
commit 07534eb144
8 changed files with 606 additions and 2 deletions

View File

@@ -120,6 +120,11 @@ class Settings(BaseSettings):
fetch_fail_pause_threshold: int = 3
fetch_max_retries: int = 2
# ===== API Push 短新闻 ingest 限速 =====
# 每个 ingest token 的滑动窗口限速(篇/秒)。2 = 短新闻一秒最多推 2 篇
# 单 token — 防止单点滥用。改小需重启 api。
ingest_rate_per_sec: int = 2
# ===== 站点并发登录 IP 限制 =====
# 限制同时在线的客户端 IP 数(防滥用 + 防 token 泄漏被滥用)
# Redis ZSET 滑动窗口:每次已认证请求刷新 score,30 天没活动自动剔除