diff --git a/src/common/utils/version.ts b/src/common/utils/version.ts index 23fb6302..de735579 100644 --- a/src/common/utils/version.ts +++ b/src/common/utils/version.ts @@ -1,40 +1,21 @@ -import { get as httpsGet } from 'node:https'; -function requestMirror(url: string): Promise { - return new Promise((resolve, reject) => { - httpsGet(url, (response) => { - let data = ''; - response.on('data', (chunk) => { - data += chunk; - }); - - response.on('end', () => { - try { - const parsedData = JSON.parse(data); - const version = parsedData.version; - resolve(version); - } catch (error) { - // 解析失败或无法访问域名,跳过 - resolve(undefined); - } - }); - }).on('error', (error) => { - // 请求失败,跳过 - resolve(undefined); - }); - }); -} - +import { logDebug } from './log'; +import { RequestUtil } from './request'; export async function checkVersion(): Promise { return new Promise(async (resolve, reject) => { const MirrorList = - [ - 'https://fastly.jsdelivr.net/gh/NapNeko/NapCatQQ@main/package.json', - 'https://gcore.jsdelivr.net/gh/NapNeko/NapCatQQ@main/package.json', - 'https://cdn.jsdelivr.us/gh/NapNeko/NapCatQQ@main/package.json', - 'https://jsd.cdn.zzko.cn/gh/NapNeko/NapCatQQ@main/package.json' - ]; + [ + 'https://fastly.jsdelivr.net/gh/NapNeko/NapCatQQ@main/package.json', + 'https://gcore.jsdelivr.net/gh/NapNeko/NapCatQQ@main/package.json', + 'https://cdn.jsdelivr.us/gh/NapNeko/NapCatQQ@main/package.json', + 'https://jsd.cdn.zzko.cn/gh/NapNeko/NapCatQQ@main/package.json' + ]; + let version = undefined; for (const url of MirrorList) { - const version = await requestMirror(url); + try { + version = (await RequestUtil.HttpGetJson<{ version: string }>(url)).version; + } catch (e) { + logDebug(e); + } if (version) { resolve(version); }