From a3ab517107d011a0dca68f01ecf3382541b5238e Mon Sep 17 00:00:00 2001 From: HDTianRu <3291691454@qq.com> Date: Sun, 18 Aug 2024 17:27:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=99=E6=AC=A1=E4=B8=80=E5=AE=9A=E6=B2=A1?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/network.js | 9 ++++++--- utils/request.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/utils/network.js b/utils/network.js index ffb1d37..9c9bc02 100644 --- a/utils/network.js +++ b/utils/network.js @@ -1,6 +1,9 @@ import fetch from 'node-fetch'; -export async function checkLatency(url, timeout = 10000) { +//暂时先写死罢( +const timeout = 5000 + +export async function checkLatency(url) { const controller = new AbortController() const { signal } = controller const timeoutId = setTimeout(() => controller.abort(), timeout) @@ -23,9 +26,9 @@ export async function checkLatency(url, timeout = 10000) { export async function findLowestLatencyUrl(urls) { const results = await Promise.allSettled(urls.map(checkLatency)); const lowestLatencyResult = results.reduce((prev, curr) => - prev.latency < curr.latency ? prev : curr + prev.value.latency < curr.value.latency ? prev : curr ); - return lowestLatencyResult.url; + return lowestLatencyResult.value.url; } export function getQueryVariable(url, variable) { diff --git a/utils/request.js b/utils/request.js index 239a28d..fbc1de2 100644 --- a/utils/request.js +++ b/utils/request.js @@ -23,7 +23,7 @@ const _request = async (url, options) => { * @param {number} retry 重试次数 * @returns {Promise} */ -const request = (url, options, retry = 0, timeout = 30000) => { +const request = (url, options, retry = 0, timeout = 15000) => { let err; const controller = new AbortController() const { signal } = controller