feat(monitor): 抖音多身份池 —— 目标按登录态串行分片
Deploy VitePress site to Pages / build (push) Canceled after 0s
Deploy VitePress site to Pages / Deploy (push) Canceled after 0s

把 44 个博主打散给多个抖音号,降低**单个账号**每轮的请求量(约 35 个博主后开始
出现限流是已知现象)。**默认串行,不是并行**:同一个出口 IP 上并发多个 cookie,
平台视角是一台设备在不停换访客,比单账号高频更容易被判异常。并发数做成了设置项,
但要先给每个账号配独立出口 IP 再考虑调大。

新增:
* `monitor_identity` 表:label / source(stored|browser) / cookie / **user_agent** /
  client_hints / status / enabled / 冷却字段。cookie 与 UA 必须成套存 —— a_bogus
  把 UA 算进签名,空 UA 签出来的请求一定被挡。
* `api/monitor/identities.py`:可用性判定、解析、**Rendezvous Hashing 分片**
  (加一个身份只迁移约 1/(n+1) 的目标)、健康状态与指数退避冷却。
* `douyin_api`:四个接口都接受显式 `identity`,走身份池时**不再回读浏览器**(否则
  浏览器里的 cookie 会把指定账号顶掉);新增 `shared_fingerprint()` 给粘贴 cookie
  的身份兜底 UA。
* `douyin_fetch.collect`:按身份分片执行,分片之间默认串行、可配切换间隔;落盘前
  按 note_id 去重(并发时两个分片可能刷到同一件作品)。
* `runner`:池模式下加载身份、不足 `identity_min_available` 就快速失败(不产生请求),
  结束后按各自分片结果回写健康。
* 设置项:identity_mode / identity_min_available / identity_switch_delay_sec /
  identity_concurrency。
* API:GET/POST/PATCH/DELETE `/api/monitor/identities` + `/{id}/check`(真请求一次,
  没有可探测博主时退化成格式检查并在 verified 里标 false)。
* 前端:设置页(仅抖音)新增「多身份(分片采集)」面板。

测试 9 条新增:分片确定性与覆盖、加身份只迁移一小部分、缺 UA/cookie 拒绝、
两次失败进冷却、成功清零、冷却中不可用、采集按身份分片。
This commit is contained in:
butubb
2026-10-22 16:37:12 +08:00
parent 4665dac667
commit d95e5ec8e2
15 changed files with 1402 additions and 65 deletions
+23
View File
@@ -7,6 +7,7 @@ import type {
MonitorComment,
MonitorCreator,
MonitorEvent,
MonitorIdentity,
MonitorNote,
MonitorOverview,
MonitorRun,
@@ -262,6 +263,28 @@ export const monitorApi = {
clearCookie: (platform?: string) =>
api.delete('/monitor/cookie', { params: { platform } }),
// --- 身份池(抖音多登录态,串行分片) ------------------------------------
listIdentities: (platform?: string) =>
api.get<{ identities: MonitorIdentity[] }>('/monitor/identities', {
params: { platform },
}),
createIdentity: (payload: {
label: string
cookie: string
user_agent?: string
platform?: string
}) => api.post<MonitorIdentity>('/monitor/identities', payload),
updateIdentity: (
id: number,
payload: Partial<{ label: string; cookie: string; user_agent: string; enabled: boolean }>,
) => api.patch<MonitorIdentity>(`/monitor/identities/${id}`, payload),
deleteIdentity: (id: number) => api.delete(`/monitor/identities/${id}`),
/** 真去请求一次,验证这份身份还能不能用。 */
checkIdentity: (id: number) =>
api.post<{ ok: boolean; verified: boolean; error: string }>(
`/monitor/identities/${id}/check`,
),
// task_id is repeated (?task_id=1&task_id=2) rather than comma-joined, so the
// query string is built by hand instead of relying on axios array encoding,
// which would emit "task_id[]=" that FastAPI does not match.