fix(proxy): skip dispatcher cache for account-level proxy URLs

This commit is contained in:
Hureru
2026-03-19 01:39:35 +08:00
parent 619df14291
commit bece34ae5b
2 changed files with 19 additions and 8 deletions
+14 -8
View File
@@ -154,19 +154,23 @@ async function getCachedSiteProxyRows(nowMs = Date.now()): Promise<SiteProxyRow[
return siteProxyCache.rows; return siteProxyCache.rows;
} }
function getDispatcherByProxyUrl(proxyUrl: string): Dispatcher | undefined { function getDispatcherByProxyUrl(proxyUrl: string, skipCache = false): Dispatcher | undefined {
const normalized = normalizeSiteProxyUrl(proxyUrl); const normalized = normalizeSiteProxyUrl(proxyUrl);
if (!normalized) return undefined; if (!normalized) return undefined;
const cached = dispatcherCache.get(normalized); if (!skipCache) {
if (cached) return cached; const cached = dispatcherCache.get(normalized);
if (cached) return cached;
}
try { try {
const parsedProxyUrl = new URL(normalized); const parsedProxyUrl = new URL(normalized);
const dispatcher = SOCKS_PROXY_PROTOCOLS.has(parsedProxyUrl.protocol.toLowerCase()) const dispatcher = SOCKS_PROXY_PROTOCOLS.has(parsedProxyUrl.protocol.toLowerCase())
? createSocksDispatcher(parsedProxyUrl) ? createSocksDispatcher(parsedProxyUrl)
: new ProxyAgent(normalized); : new ProxyAgent(normalized);
dispatcherCache.set(normalized, dispatcher); if (!skipCache) {
dispatcherCache.set(normalized, dispatcher);
}
return dispatcher; return dispatcher;
} catch { } catch {
return undefined; return undefined;
@@ -413,7 +417,7 @@ export async function withSiteProxyRequestInit(
return nextOptions; return nextOptions;
} }
const dispatcher = getDispatcherByProxyUrl(proxyUrl); const dispatcher = getDispatcherByProxyUrl(proxyUrl, alsOverride != null);
if (!dispatcher) { if (!dispatcher) {
return nextOptions; return nextOptions;
} }
@@ -427,11 +431,12 @@ export async function withSiteProxyRequestInit(
export function withExplicitProxyRequestInit( export function withExplicitProxyRequestInit(
proxyUrl: string | null | undefined, proxyUrl: string | null | undefined,
options?: UndiciRequestInit, options?: UndiciRequestInit,
skipCache = false,
): UndiciRequestInit { ): UndiciRequestInit {
const normalized = normalizeSiteProxyUrl(proxyUrl); const normalized = normalizeSiteProxyUrl(proxyUrl);
if (!normalized) return options ?? {}; if (!normalized) return options ?? {};
const dispatcher = getDispatcherByProxyUrl(normalized); const dispatcher = getDispatcherByProxyUrl(normalized, skipCache);
if (!dispatcher) return options ?? {}; if (!dispatcher) return options ?? {};
return { return {
@@ -457,8 +462,9 @@ export function withSiteRecordProxyRequestInit(
if (mergedHeaders) { if (mergedHeaders) {
nextOptions.headers = mergedHeaders; nextOptions.headers = mergedHeaders;
} }
const proxyUrl = normalizeSiteProxyUrl(accountProxyUrl) || resolveProxyUrlForSite(site); const accountNormalized = normalizeSiteProxyUrl(accountProxyUrl);
return withExplicitProxyRequestInit(proxyUrl, nextOptions); const proxyUrl = accountNormalized || resolveProxyUrlForSite(site);
return withExplicitProxyRequestInit(proxyUrl, nextOptions, !!accountNormalized);
} }
export function resolveChannelProxyUrl( export function resolveChannelProxyUrl(
+5
View File
@@ -2235,6 +2235,11 @@ body[data-tooltip-portal="true"] [data-tooltip]::before {
color: var(--color-text-muted); color: var(--color-text-muted);
} }
[data-theme="dark"] .badge-purple {
background: #2e1065;
color: #c4b5fd;
}
[data-theme="dark"] .badge-link:hover .badge-muted, [data-theme="dark"] .badge-link:hover .badge-muted,
[data-theme="dark"] .badge-link:focus-visible .badge-muted { [data-theme="dark"] .badge-link:focus-visible .badge-muted {
background: rgba(96, 165, 250, 0.2); background: rgba(96, 165, 250, 0.2);