From bf36f0e53ce964e7a914e288ba4fb884268861f2 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Mon, 24 Mar 2025 19:20:52 -0300 Subject: [PATCH 05/17] feat: add support for multiple proxies --- src/lib/helpers/getFetchClient.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lib/helpers/getFetchClient.ts b/src/lib/helpers/getFetchClient.ts index 7bdee90..4f657e1 100644 --- a/src/lib/helpers/getFetchClient.ts +++ b/src/lib/helpers/getFetchClient.ts @@ -7,13 +7,28 @@ type FetchInitParameterWithClient = | RequestInit & { client: Deno.HttpClient }; type FetchReturn = ReturnType; +let proxies: string[] = []; +let proxyData: string; +try { + proxyData = Deno.readTextFileSync("proxies.txt"); + proxies = proxyData.split("\n").map((line) => line.trim()).filter((line) => + line.length > 0 + ); + console.log("[INFO] Number of proxies on the list:", proxies.length); +} catch (error) { + console.error("[ERROR] Error reading proxy file:", error); + console.log("[INFO] Proxies from a list of proxies will not be used"); +} + export const getFetchClient = (config: Config): { ( input: FetchInputParameter, init?: FetchInitParameterWithClient, ): FetchReturn; } => { - const proxyAddress = config.networking.proxy; + const proxyAddress = config.networking.proxy || + (proxies.length > 0 ? proxies[Math.floor(Math.random() *proxies.length)] : null); + if (proxyAddress) { return async ( input: FetchInputParameter, -- 2.49.0