feat: add per-API connection proxy URL settings

This commit is contained in:
lzt404 committed 2026-09-25 14:51:56 +08:00
1 parent 2432220677
commit 4d2aea3353
9 files changed
+196 -7

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
export function normalizeProviderProxyUrl(value: string): string {
const proxyUrl = value.trim();
if (!proxyUrl) return '';
if (/^(direct|none)$/i.test(proxyUrl)) return proxyUrl.toLowerCase();
try {
if (/\s/.test(proxyUrl)) throw new Error('invalid');
const url = new URL(proxyUrl);
if (!['http:', 'https:', 'socks5:', 'socks5h:'].includes(url.protocol)
|| !url.hostname
|| (!url.port && !['http:', 'https:'].includes(url.protocol))
|| !['', '/'].includes(url.pathname)
|| url.search
|| url.hash) {
throw new Error('invalid');
}
} catch {
throw new Error('invalid');
}
return proxyUrl;
}