尝试解决图片第一次下载失败后无法自动解决图片裂开问题&驱动盘序号错位问题

This commit is contained in:
bietiaop 2024-08-14 20:46:13 +08:00
parent 8304b8bffa
commit 839ca76855
6 changed files with 153 additions and 56 deletions

View file

@ -1,6 +1,5 @@
import http from 'http';
import https from 'https';
import fetch from 'node-fetch';
export async function checkLatency(url) {
let request = http;
if (url.startsWith('https')) {
@ -36,20 +35,3 @@ export function getQueryVariable(url, variable) {
const key = searchParams.get(variable);
return key;
}
export async function fetchWithRetry(url, options, retry = 3) {
let err;
const _fetch = async (url, options, retryCount = 0) => {
if (retryCount > retry) {
throw new Error('Retry limit reached', err);
}
try {
return await fetch(url, options);
} catch (error) {
logger.debug(`Fetch error: ${error.message}`);
err = error;
return _fetch(url, options, retryCount + 1);
}
};
return _fetch(url, options);
}