/** * 采集层的 HTTP 基建。 * * 这里只做三件事,但每件都是采集能不能活下来的关键: * 1. **超时**:单个源卡住不能拖垮整轮采集。用 AbortSignal.timeout,外部 signal 也一并接上。 * 2. **退避重试**:只对"值得重试"的失败重试(网络错误、429、5xx)。 * 4xx(除了 429)直接放弃 —— 拿 403 重试三次只是浪费用户 30 秒。 * 3. **默认头**:不少站(尤其哔哩哔哩)对无 UA 的请求直接风控。 */ export declare class HttpError extends Error { readonly status: number; readonly url: string; constructor(message: string, status: number, url: string); } export interface FetchOptions { timeoutMs?: number; /** 额外重试次数(不含首次)。默认 2。 */ retries?: number; headers?: Record; signal?: AbortSignal; /** 部分源(哔哩哔哩)要求同站 Referer,否则 403 / 风控。 */ referer?: string; } /** 把一次 HTTP 取文本的语义收干净:非 2xx 抛 HttpError,网络错误原样抛。 */ export declare function fetchText(url: string, options?: FetchOptions): Promise; export declare function fetchJson(url: string, options?: FetchOptions): Promise; /** 简单的并发闸门:抓取轮次用它限制同时在飞的请求数。 */ export declare function mapLimit(items: readonly T[], limit: number, mapper: (item: T, index: number) => Promise): Promise>>;