From ed55a5a54cb32e6e318885c0f45da911f325062e Mon Sep 17 00:00:00 2001 From: idranme Date: Thu, 12 Sep 2024 17:52:21 +0800 Subject: [PATCH] optimize --- src/common/utils/upgrade.ts | 28 +++++++++++++++++++++------- src/onebot11/entities.ts | 4 ++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/common/utils/upgrade.ts b/src/common/utils/upgrade.ts index d47f9f9..66c80f2 100644 --- a/src/common/utils/upgrade.ts +++ b/src/common/utils/upgrade.ts @@ -6,6 +6,7 @@ import { copyFolder, log, fetchFile } from '.' import { PLUGIN_DIR, TEMP_DIR } from '../globalVars' const downloadMirrorHosts = ['https://ghp.ci/'] +const releasesMirrorHosts = ['https://kkgithub.com'] export async function checkNewVersion() { const latestVersionText = await getRemoteVersion() @@ -74,16 +75,22 @@ export async function upgradeLLOneBot() { } export async function getRemoteVersion() { - let version = '' - const mirrorGithub = downloadMirrorHosts[0] - const tVersion = await getRemoteVersionByMirror(mirrorGithub) - if (tVersion) { - version = tVersion + for (const mirror of releasesMirrorHosts) { + const version = await getRemoteVersionByReleasesMirror(mirror) + if (version) { + return version + } } - return version + for (const mirror of downloadMirrorHosts) { + const version = await getRemoteVersionByDownloadMirror(mirror) + if (version) { + return version + } + } + return '' } -export async function getRemoteVersionByMirror(mirrorGithub: string) { +export async function getRemoteVersionByDownloadMirror(mirrorGithub: string) { try { const source = 'https://raw.githubusercontent.com/LLOneBot/LLOneBot/main/src/version.ts' const page = (await fetchFile(mirrorGithub + source)).data.toString() @@ -92,3 +99,10 @@ export async function getRemoteVersionByMirror(mirrorGithub: string) { log(e?.toString()) } } + +export async function getRemoteVersionByReleasesMirror(mirrorGithub: string) { + try { + const page = (await fetchFile(mirrorGithub + '/LLOneBot/LLOneBot/releases')).data.toString() + return page.match(new RegExp('(?<=(tag/v)).*?(?=("))'))?.[0] + } catch { } +} diff --git a/src/onebot11/entities.ts b/src/onebot11/entities.ts index 68b04a1..ffc6846 100644 --- a/src/onebot11/entities.ts +++ b/src/onebot11/entities.ts @@ -489,7 +489,7 @@ export namespace OB11Entities { } } else if (element.fileElement) { - return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin!), { + return new OB11GroupUploadNoticeEvent(+msg.peerUid, +msg.senderUin!, { id: element.fileElement.fileUuid!, name: element.fileElement.fileName, size: parseInt(element.fileElement.fileSize), @@ -587,7 +587,7 @@ export namespace OB11Entities { { txt: '头衔', type: 'nor' } ] } - + * */ if (grayTipElement.jsonGrayTipElement.busiId == 1061) { //判断业务类型