invidious-companion-patches/patches/0006-feat-add-support-for-multiple-proxies.patch
Fijxu 5384b8b0e4
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m45s
add patch metrics-add-live-premiere-and-private-video-errors.patch
2025-04-20 02:22:55 -04:00

46 lines
1.6 KiB
Diff

From 9aaa709981c487b8b0e27ac599b14e5482db70d6 Mon Sep 17 00:00:00 2001
From: Fijxu <fijxu@nadeko.net>
Date: Mon, 24 Mar 2025 19:20:52 -0300
Subject: [PATCH 06/16] 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