mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-17 05:37:46 +00:00
这次一定没问题了
This commit is contained in:
parent
2841131dd0
commit
a3ab517107
2 changed files with 7 additions and 4 deletions
|
|
@ -1,6 +1,9 @@
|
||||||
import fetch from 'node-fetch';
|
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 controller = new AbortController()
|
||||||
const { signal } = controller
|
const { signal } = controller
|
||||||
const timeoutId = setTimeout(() => controller.abort(), timeout)
|
const timeoutId = setTimeout(() => controller.abort(), timeout)
|
||||||
|
|
@ -23,9 +26,9 @@ export async function checkLatency(url, timeout = 10000) {
|
||||||
export async function findLowestLatencyUrl(urls) {
|
export async function findLowestLatencyUrl(urls) {
|
||||||
const results = await Promise.allSettled(urls.map(checkLatency));
|
const results = await Promise.allSettled(urls.map(checkLatency));
|
||||||
const lowestLatencyResult = results.reduce((prev, curr) =>
|
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) {
|
export function getQueryVariable(url, variable) {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ const _request = async (url, options) => {
|
||||||
* @param {number} retry 重试次数
|
* @param {number} retry 重试次数
|
||||||
* @returns {Promise<Response>}
|
* @returns {Promise<Response>}
|
||||||
*/
|
*/
|
||||||
const request = (url, options, retry = 0, timeout = 30000) => {
|
const request = (url, options, retry = 0, timeout = 15000) => {
|
||||||
let err;
|
let err;
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
const { signal } = controller
|
const { signal } = controller
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue