Spaces:
Paused
Paused
File size: 658 Bytes
87fc763 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import type { Dispatcher } from "undici";
import { ProxyAgent, fetch as undiciFetch } from "undici";
import type { ZaloFetch } from "./api.js";
const proxyCache = new Map<string, ZaloFetch>();
export function resolveZaloProxyFetch(proxyUrl?: string | null): ZaloFetch | undefined {
const trimmed = proxyUrl?.trim();
if (!trimmed) {
return undefined;
}
const cached = proxyCache.get(trimmed);
if (cached) {
return cached;
}
const agent = new ProxyAgent(trimmed);
const fetcher: ZaloFetch = (input, init) =>
undiciFetch(input, { ...init, dispatcher: agent as Dispatcher });
proxyCache.set(trimmed, fetcher);
return fetcher;
}
|