mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: check for updates
This commit is contained in:
parent
2ac2c68435
commit
1132495eb3
@ -5,20 +5,21 @@ import { version } from '../../version'
|
||||
import { copyFolder, log, fetchFile } from '.'
|
||||
import { PLUGIN_DIR, TEMP_DIR } from '../globalVars'
|
||||
|
||||
const downloadMirrorHosts = ['https://mirror.ghproxy.com/']
|
||||
const checkVersionMirrorHosts = ['https://kkgithub.com']
|
||||
const downloadMirrorHosts = ['https://ghp.ci/']
|
||||
|
||||
export async function checkNewVersion() {
|
||||
const latestVersionText = await getRemoteVersion()
|
||||
const latestVersion = latestVersionText.split('.')
|
||||
//log('llonebot last version', latestVersion)
|
||||
const currentVersion: string[] = version.split('.')
|
||||
log('LLOneBot latest version', latestVersion)
|
||||
const currentVersion = version.split('.')
|
||||
//log('llonebot current version', currentVersion)
|
||||
for (const k of [0, 1, 2]) {
|
||||
if (parseInt(latestVersion[k]) > parseInt(currentVersion[k])) {
|
||||
const latest = parseInt(latestVersion[k])
|
||||
const current = parseInt(currentVersion[k])
|
||||
if (latest > current) {
|
||||
log('')
|
||||
return { result: true, version: latestVersionText }
|
||||
} else if (parseInt(latestVersion[k]) < parseInt(currentVersion[k])) {
|
||||
} else if (latest < current) {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -28,7 +29,7 @@ export async function checkNewVersion() {
|
||||
export async function upgradeLLOneBot() {
|
||||
const latestVersion = await getRemoteVersion()
|
||||
if (latestVersion && latestVersion != '') {
|
||||
const downloadUrl = 'https://github.com/LLOneBot/LLOneBot/releases/download/v' + latestVersion + '/LLOneBot.zip'
|
||||
const downloadUrl = `https://github.com/LLOneBot/LLOneBot/releases/download/v${latestVersion}/LLOneBot.zip`
|
||||
const filePath = path.join(TEMP_DIR, './update-' + latestVersion + '.zip')
|
||||
let downloadSuccess = false
|
||||
// 多镜像下载
|
||||
@ -73,26 +74,21 @@ export async function upgradeLLOneBot() {
|
||||
}
|
||||
|
||||
export async function getRemoteVersion() {
|
||||
let Version = ''
|
||||
for (let i = 0; i < checkVersionMirrorHosts.length; i++) {
|
||||
const mirrorGithub = checkVersionMirrorHosts[i]
|
||||
const tVersion = await getRemoteVersionByMirror(mirrorGithub)
|
||||
if (tVersion && tVersion != '') {
|
||||
Version = tVersion
|
||||
break
|
||||
}
|
||||
let version = ''
|
||||
const mirrorGithub = downloadMirrorHosts[0]
|
||||
const tVersion = await getRemoteVersionByMirror(mirrorGithub)
|
||||
if (tVersion) {
|
||||
version = tVersion
|
||||
}
|
||||
return Version
|
||||
return version
|
||||
}
|
||||
|
||||
export async function getRemoteVersionByMirror(mirrorGithub: string) {
|
||||
let releasePage = 'error'
|
||||
|
||||
try {
|
||||
releasePage = (await fetchFile(mirrorGithub + '/LLOneBot/LLOneBot/releases')).data.toString()
|
||||
// log("releasePage", releasePage);
|
||||
if (releasePage === 'error') return ''
|
||||
return releasePage.match(new RegExp('(?<=(tag/v)).*?(?=("))'))?.[0]
|
||||
} catch { }
|
||||
return ''
|
||||
const source = 'https://raw.githubusercontent.com/LLOneBot/LLOneBot/main/src/version.ts'
|
||||
const page = (await fetchFile(mirrorGithub + source)).data.toString()
|
||||
return page.match(/(\d+\.\d+\.\d+)/)?.[0]
|
||||
} catch (e) {
|
||||
log(e?.toString())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user