All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m15s
46 lines
1.6 KiB
Diff
46 lines
1.6 KiB
Diff
From 13fd8adcfc0a4a5f02dca24e8dfa7f89412c8c8e Mon Sep 17 00:00:00 2001
|
|
From: Fijxu <fijxu@nadeko.net>
|
|
Date: Mon, 24 Mar 2025 19:20:52 -0300
|
|
Subject: [PATCH 06/12] 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<typeof fetch>;
|
|
|
|
+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
|
|
|