diff --git a/web/static/js/proxy-settings.js b/web/static/js/proxy-settings.js index b9b72839..9ea60130 100644 --- a/web/static/js/proxy-settings.js +++ b/web/static/js/proxy-settings.js @@ -30,8 +30,9 @@ async function saveProxySettings() { for (const key of ['mode', 'proxy_url', 'proxy_pool', 'proxy_source', 'strategy']) proxy[key] = document.getElementById(`proxy-setting-${key}`).value.trim(); for (const key of ['max_attempts', 'cooldown', 'min_switch_interval']) { const input = document.getElementById(`proxy-setting-${key}`); - if (!input.checkValidity() || input.value === '') throw new Error(window.t('proxySettings.invalidNumber')); - proxy[key] = Number(input.value); + const valid = input.checkValidity() && input.value !== ''; + if (!valid && proxy.mode === 'pool') throw new Error(window.t('proxySettings.invalidNumber')); + proxy[key] = valid ? Number(input.value) : ({max_attempts: 3, cooldown: 60, min_switch_interval: 60})[key]; } const response = await apiFetch('/api/config', {method: 'PUT', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({proxy})}); if (!response.ok) throw new Error((await response.json()).error || window.t('proxySettings.saveError')); diff --git a/web/static/js/proxy-settings.test.cjs b/web/static/js/proxy-settings.test.cjs index 1eb8995f..f8d616a2 100644 --- a/web/static/js/proxy-settings.test.cjs +++ b/web/static/js/proxy-settings.test.cjs @@ -23,3 +23,13 @@ test('masked credentials survive save without restarting other services',async() assert.equal(f.calls.some(x=>x.url==='/api/config/apply'),false); assert.equal(f.elements['proxy-settings-save'].disabled,false); }); +test('hidden pool validation does not prevent switching to a fixed proxy',async()=>{ + const f=fixture({mode:'pool'});await f.ctx.loadProxySettings(); + f.elements['proxy-setting-max_attempts'].value=''; + f.elements['proxy-setting-max_attempts'].checkValidity=()=>false; + f.elements['proxy-setting-mode'].value='fixed'; + f.elements['proxy-setting-proxy_url'].value='http://localhost:8080'; + await f.ctx.saveProxySettings(); + const write=f.calls.find(x=>x.options?.method==='PUT');assert.ok(write); + assert.equal(JSON.parse(write.options.body).proxy.max_attempts,3); +});