mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-08 03:59:00 +08:00
refactor: check version
This commit is contained in:
parent
b795e6c3d2
commit
32bdf10fd2
@ -1,40 +1,21 @@
|
|||||||
import { get as httpsGet } from 'node:https';
|
import { logDebug } from './log';
|
||||||
function requestMirror(url: string): Promise<string | undefined> {
|
import { RequestUtil } from './request';
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function checkVersion(): Promise<string> {
|
export async function checkVersion(): Promise<string> {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const MirrorList =
|
const MirrorList =
|
||||||
[
|
[
|
||||||
'https://fastly.jsdelivr.net/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://gcore.jsdelivr.net/gh/NapNeko/NapCatQQ@main/package.json',
|
||||||
'https://cdn.jsdelivr.us/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://jsd.cdn.zzko.cn/gh/NapNeko/NapCatQQ@main/package.json'
|
||||||
];
|
];
|
||||||
|
let version = undefined;
|
||||||
for (const url of MirrorList) {
|
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) {
|
if (version) {
|
||||||
resolve(version);
|
resolve(version);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user