增加版本信息获取工具类.

可以在项目代码中直接使用 import um = require('UpdateManager') 然后调用相关接口.
This commit is contained in:
andrewlu
2021-02-03 21:34:58 +08:00
parent ae6566c8dd
commit ef915a121e
10 changed files with 201 additions and 84 deletions

View File

@@ -79,11 +79,11 @@ class FileUploader {
if (this.ftps[i].totalTasks && !this.ftps[i].idleState) {
p = (this.ftps[i].totalTasks - this.ftps[i].queue.length) / this.ftps[i].totalTasks;
}
p = Math.floor(p * 10000) / 100;
p = parseFloat((Math.floor(p * 10000) / 100).toFixed(2));
str.push({
name: i,
idle: this.ftps[i].idleState,
remain: this.ftps[i].queue.length,
remain: this.ftps[i].getTaskLength(),
hasError: this.ftps[i].hasError,
totalTasks: this.ftps[i].totalTasks,
curTaskPath: this.ftps[i].curTaskPath,
@@ -240,7 +240,15 @@ class UploadThread {
uploadOnce(ftp, once) {
return Promise.race([new Promise(function (resolve) {
ftp.put(once.src, once.dst, false, resolve)
fs.readFile(once.src, (err, data) => {
if (err) {
logger.error('文件读取异常:', once.src, err);
resolve(err)
return
} else {
ftp.put(data, once.dst, false, resolve)
}
});
}), this.sleep(20000)]);
}

View File

@@ -34,15 +34,13 @@ class FileUtil {
* @param src
* @param dst
*/
copy(src, dst) {
async copy(src, dst) {
const st = fs.statSync(src);
if (st.isFile()) {
var readable = fs.createReadStream(src);//创建读取流
var writable = fs.createWriteStream(dst);//创建写入流
const readable = fs.createReadStream(src);//创建读取流
const writable = fs.createWriteStream(dst);//创建写入流
readable.pipe(writable);
return;
} else if (!st.isDirectory()) {
return;
}
if (!fs.existsSync(dst)) {
fs.mkdirSync(dst, {recursive: true});
@@ -56,7 +54,6 @@ class FileUtil {
write(filePath, content) {
const pathInfo = path.parse(filePath);
// console.log('写文件:', filePath, pathInfo.dir)
if (!fs.existsSync(pathInfo.dir)) {
fs.mkdirSync(pathInfo.dir, {recursive: true});
}