diff options
| author | Larvan2 <[email protected]> | 2026-06-04 21:14:57 +0800 |
|---|---|---|
| committer | Larvan2 <[email protected]> | 2026-06-04 21:14:57 +0800 |
| commit | cc6efa25afc9853771565a5f68d1cc24b3a945b2 (patch) | |
| tree | b428b0aec1f183d2c2bddbba45f081bede7f1da5 /src/api | |
| parent | 64e7ca292446242c4769b8e54bd4db048eb46170 (diff) | |
feat(proxies): add latency test URL and timeout configuration
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/proxies.ts | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/api/proxies.ts b/src/api/proxies.ts index 302014c..9def763 100644 --- a/src/api/proxies.ts +++ b/src/api/proxies.ts @@ -35,10 +35,11 @@ export async function requestToSwitchProxy(apiConfig, name1, name2) { export async function requestDelayForProxy( apiConfig, name, - latencyTestUrl = 'https://www.gstatic.com/generate_204' + latencyTestUrl = 'https://www.gstatic.com/generate_204', + timeout = 5000 ) { const { url, init } = getURLAndInit(apiConfig); - const qs = `timeout=5000&url=${encodeURIComponent(latencyTestUrl)}`; + const qs = `timeout=${timeout}&url=${encodeURIComponent(latencyTestUrl)}`; const fullURL = `${url}${endpoint}/${encodeURIComponent(name)}/delay?${qs}`; return await fetch(fullURL, init); } @@ -46,10 +47,11 @@ export async function requestDelayForProxy( export async function requestDelayForProxyGroup( apiConfig, name, - latencyTestUrl = 'http://www.gstatic.com/generate_202' + latencyTestUrl = 'https://www.gstatic.com/generate_204', + timeout = 5000 ) { const { url, init } = getURLAndInit(apiConfig); - const qs = `url=${encodeURIComponent(latencyTestUrl)}&timeout=2000`; + const qs = `url=${encodeURIComponent(latencyTestUrl)}&timeout=${timeout}`; const fullUrl = `${url}/group/${encodeURIComponent(name)}/delay?${qs}`; return await fetch(fullUrl, init); } @@ -81,14 +83,17 @@ export async function healthcheckProviderByName(config, name) { export async function healthcheckProviderProxy( config: ClashAPIConfig, providerName: string, - proxyName: string + proxyName: string, + latencyTestUrl = 'https://www.gstatic.com/generate_204', + timeout = 5000 ) { const { url, init } = getURLAndInit(config); + const qs = `timeout=${timeout}&url=${encodeURIComponent(latencyTestUrl)}`; const options = { ...init, method: 'GET' }; return await fetch( `${url}/providers/proxies/${encodeURIComponent(providerName)}/${encodeURIComponent( proxyName - )}/healthcheck`, + )}/healthcheck?${qs}`, options ); } |
