mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: add timeout on speedtest API fetching
This commit is contained in:
@@ -13,7 +13,7 @@ import { getGorhillPublicSuffixPromise } from './lib/get-gorhill-publicsuffix';
|
||||
const s = new Sema(3);
|
||||
|
||||
const latestTopUserAgentsPromise = fetchWithRetry('https://unpkg.com/top-user-agents@latest/index.json')
|
||||
.then(res => res.json() as Promise<string[]>);
|
||||
.then(res => res.json<string[]>());
|
||||
|
||||
const querySpeedtestApi = async (keyword: string): Promise<Array<string | null>> => {
|
||||
const topUserAgents = (await Promise.all([
|
||||
@@ -39,13 +39,17 @@ const querySpeedtestApi = async (keyword: string): Promise<Array<string | null>>
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'Sec-Gpc': '1'
|
||||
}
|
||||
},
|
||||
retry: {
|
||||
retryOnAborted: true
|
||||
},
|
||||
signal: AbortSignal.timeout(4000)
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`${res.statusText}\n${await res.text()}`);
|
||||
}
|
||||
|
||||
const json = await res.json() as Array<{ url: string }>;
|
||||
const json = await res.json<Array<{ url: string }>>();
|
||||
|
||||
s.release();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user