mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat:check update
This commit is contained in:
@@ -9,7 +9,7 @@ export * from './qqpkg'
|
||||
export * from './update'
|
||||
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
||||
export const TEMP_DIR = path.join(DATA_DIR, "temp");
|
||||
|
||||
export const PLUGIN_DIR = global.LiteLoader.plugins["LLOneBot"].path.plugin;
|
||||
if (!fs.existsSync(TEMP_DIR)) {
|
||||
fs.mkdirSync(TEMP_DIR);
|
||||
}
|
@@ -3,7 +3,8 @@ import https from "node:https";
|
||||
//import http from "node:http";
|
||||
import * as path from "node:path";
|
||||
import * as fs from "node:fs";
|
||||
import { TEMP_DIR } from ".";
|
||||
import { PLUGIN_DIR, TEMP_DIR } from ".";
|
||||
import compressing from "compressing";
|
||||
export async function checkVersion() {
|
||||
const latestVersionText = await getRemoteVersion();
|
||||
const latestVersion = latestVersionText.split(".");
|
||||
@@ -23,9 +24,37 @@ export async function updateLLOneBot() {
|
||||
const realUrl = mirrorGithubList[0] + downloadUrl;
|
||||
const filePath = path.join(TEMP_DIR, "./update-" + latestVersion + ".zip");
|
||||
const fileStream = fs.createWriteStream(filePath);
|
||||
https.get(realUrl, (res) => {
|
||||
res.pipe(fileStream);
|
||||
})
|
||||
let downloadPromise = async function (filePath): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
https.get(filePath, res => {
|
||||
res.pipe(fileStream);
|
||||
res.on('end', () => {
|
||||
resolve(true);
|
||||
});
|
||||
}).on('error', err => {
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (!(await downloadPromise(realUrl))) {
|
||||
// 下载异常
|
||||
return false;
|
||||
}
|
||||
let uncompressPromise = async function () {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
compressing.zip.uncompress(filePath, PLUGIN_DIR).then(() => {
|
||||
resolve(true);
|
||||
}).catch((reason: any) => {
|
||||
console.log(reason);
|
||||
if (reason?.errno == -4082) {
|
||||
resolve(true);
|
||||
}
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
const uncompressResult = await uncompressPromise();
|
||||
return uncompressResult;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user