aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workers/utils.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-10-12 22:25:29 +0100
committerGitHub <noreply@github.com>2025-10-12 22:25:29 +0100
commitc14b69346a67d4c426d7ddb32ef32812c449e67c (patch)
treeb191791b6b467c8d25398b6b33b40fb7aa113dac /apps/workers/utils.ts
parent88a7ffec019d6cb5f78b8bc39d742fc8540ff811 (diff)
downloadkarakeep-c14b69346a67d4c426d7ddb32ef32812c449e67c.tar.zst
feat: support passing multiple proxy values (#2039)
* feat: support passing multiple proxy values * fix typo * trim and filter
Diffstat (limited to 'apps/workers/utils.ts')
-rw-r--r--apps/workers/utils.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/apps/workers/utils.ts b/apps/workers/utils.ts
index 55204570..a82dd12d 100644
--- a/apps/workers/utils.ts
+++ b/apps/workers/utils.ts
@@ -21,6 +21,10 @@ export function withTimeout<T, Ret>(
};
}
+export function getRandomProxy(proxyList: string[]): string {
+ return proxyList[Math.floor(Math.random() * proxyList.length)].trim();
+}
+
function getProxyAgent(url: string) {
const { proxy } = serverConfig;
@@ -48,12 +52,14 @@ function getProxyAgent(url: string) {
}
if (protocol === "https:" && proxy.httpsProxy) {
- return new HttpsProxyAgent(proxy.httpsProxy);
+ const selectedProxy = getRandomProxy(proxy.httpsProxy);
+ return new HttpsProxyAgent(selectedProxy);
} else if (protocol === "http:" && proxy.httpProxy) {
- return new HttpProxyAgent(proxy.httpProxy);
+ const selectedProxy = getRandomProxy(proxy.httpProxy);
+ return new HttpProxyAgent(selectedProxy);
} else if (proxy.httpProxy) {
- // Fallback to HTTP proxy for HTTPS if HTTPS proxy not configured
- return new HttpProxyAgent(proxy.httpProxy);
+ const selectedProxy = getRandomProxy(proxy.httpProxy);
+ return new HttpProxyAgent(selectedProxy);
}
return undefined;