mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-23 04:09:49 +00:00
feat(proxy-pools): auto-rotate strategy for no-auth providers (#2409)
Add round-robin/random proxy pool rotation for no-auth free providers (e.g. OpenCode Free) to distribute load across all active pools and avoid per-IP rate limits. Rotation strategy is selectable per provider in NoAuthProxyCard and persisted to settings.providerStrategies.
This commit is contained in:
committed by
decolua
parent
f1f9d27061
commit
e1f3399b73
@@ -6,6 +6,33 @@ function normalizeString(value) {
|
||||
return String(value).trim();
|
||||
}
|
||||
|
||||
// ─── Proxy pool rotation state (in-memory) ─────────────────────────
|
||||
const rotateState = new Map(); // providerId → { index }
|
||||
|
||||
/**
|
||||
* Pick one proxy pool ID from a list based on strategy.
|
||||
* round-robin: cycle sequentially (in-memory, resets on restart)
|
||||
* random: uniform random pick
|
||||
* none/single: return first entry
|
||||
*/
|
||||
export function pickProxyPoolId(poolIds, strategy, providerId) {
|
||||
if (!poolIds || poolIds.length === 0) return null;
|
||||
if (poolIds.length === 1) return poolIds[0];
|
||||
|
||||
if (strategy === "round-robin") {
|
||||
const state = rotateState.get(providerId) || { index: -1 };
|
||||
state.index = (state.index + 1) % poolIds.length;
|
||||
rotateState.set(providerId, state);
|
||||
return poolIds[state.index];
|
||||
}
|
||||
|
||||
if (strategy === "random") {
|
||||
return poolIds[Math.floor(Math.random() * poolIds.length)];
|
||||
}
|
||||
|
||||
return poolIds[0]; // "none" or unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize legacy proxy configuration.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user