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