Skip to content

Commit

Permalink
优化日志
Browse files Browse the repository at this point in the history
  • Loading branch information
masx200 committed Sep 18, 2020
1 parent 5f028b5 commit d229cd0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 27 deletions.
24 changes: 20 additions & 4 deletions lib/uploadfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ const successmsg = [
import baidupcsupload from "./execbaidupcs.js";
const successerror = ["panic: runtime error: index out of range"];
export async function upload(file, destination) {
const starttime = Date.now();
let result = { stdout: "", stderr: "" };
function done() {
const endtime = Date.now();
const durtime = (endtime - starttime) / 1000;
console.log(["初步文件上传成功", file, destination].join("\n"));
console.log("用时" + durtime + "秒");
return;
}
try {
result = await baidupcsupload(file, destination);
} catch (error) {
Expand All @@ -46,7 +54,7 @@ export async function upload(file, destination) {
successerror.some((m) => stderr?.includes(m)) &&
successmsg.some((m) => stdout?.includes(m))
) {
console.log("初步文件上传成功", file, destination);
done();
return;
} else {
throw error;
Expand All @@ -69,7 +77,7 @@ export async function upload(file, destination) {
console.warn("上传失败,5秒后重试:" + file);
return await retryupload(file, destination);
} else if (successmsg.some((m) => stdout.includes(m))) {
console.log("初步文件上传成功", file, destination);
done();
return;
} else if (retrymsg.some((msg) => stdout.includes(msg))) {
console.warn(stdout, stderr);
Expand Down Expand Up @@ -101,15 +109,23 @@ export async function uploadandcheck(file, destination) {
await upload(file, destination);
const inputbase = path.basename(file);
const remotefile = posix.join(destination, inputbase);
const starttime = Date.now();
const fileexist = await checkexist(remotefile);
if (fileexist) {
console.log(
"检查网盘中存在此文件,上传文件成功:" + file + " " + remotefile
["检查网盘中存在此文件,上传文件成功:", file, remotefile].join(
"\n"
)
);
const endtime = Date.now();
const durtime = (endtime - starttime) / 1000;
console.log("用时" + durtime + "秒");
return;
} else {
console.warn(
"检查网盘中不存在此文件,重新上传文件:" + file + " " + remotefile
["检查网盘中不存在此文件,重新上传文件:", file, remotefile].join(
"\n"
)
);
return await retryupload(file, destination);
}
Expand Down
49 changes: 26 additions & 23 deletions lib/uploadfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,19 @@ const successerror = ["panic: runtime error: index out of range"];
export async function upload(file: string, destination: string): Promise<void> {
// const localfile = file;
// const desdir = destination;
const starttime=Date.now()
const starttime = Date.now();

let result = { stdout: "", stderr: "" };
function done(){
const endtime=Date.now()
const durtime=(endtime-starttime)/1000
function done() {
const endtime = Date.now();
const durtime = (endtime - starttime) / 1000;

console.log(["初步文件上传成功", file, destination].join("\n"));

console.log(["初步文件上传成功", file, destination,].join("\n"));
console.log("用时" + durtime + "秒");

console.log("用时"+durtime+"秒")

return
}
return;
}
try {
result = await baidupcsupload(file, destination);
} catch (error) {
Expand Down Expand Up @@ -99,7 +98,7 @@ Error: Command failed: BaiduPCS-Go.exe upload D:\baidupandownload\微博美图
successerror.some((m) => stderr?.includes(m)) &&
successmsg.some((m) => stdout?.includes(m))
) {
/*
/*
const endtime=Date.now()
const durtime=(endtime-starttime)/1000
Expand All @@ -108,8 +107,8 @@ const durtime=(endtime-starttime)/1000
console.log("用时"+durtime+"秒")
*/
done()
return;
done();
return;
} else {
//如果。找不到 baidupcs-go的可执行文件,则。会在这里报错
throw error;
Expand Down Expand Up @@ -147,10 +146,10 @@ return;
console.warn("上传失败,5秒后重试:" + file);
return await retryupload(file, destination);
} else if (successmsg.some((m) => stdout.includes(m))) {
// console.log("初步文件上传成功", file, destination);
done()
return;
// console.log("初步文件上传成功", file, destination);

done();
return;
} else if (retrymsg.some((msg) => stdout.includes(msg))) {
console.warn(stdout, stderr);
console.warn("上传失败,5秒后重试:" + file);
Expand Down Expand Up @@ -190,19 +189,23 @@ export async function uploadandcheck(

const inputbase = path.basename(file);
const remotefile = posix.join(destination, inputbase);
const starttime=Date.now()
const fileexist = await checkexist(remotefile);
const starttime = Date.now();
const fileexist = await checkexist(remotefile);
if (fileexist) {
console.log(
["检查网盘中存在此文件,上传文件成功:" , file , remotefile].join("\n")
["检查网盘中存在此文件,上传文件成功:", file, remotefile].join(
"\n"
)
);
const endtime=Date.now()
const durtime=(endtime-starttime)/1000
console.log("用时"+durtime+"秒")
const endtime = Date.now();
const durtime = (endtime - starttime) / 1000;
console.log("用时" + durtime + "秒");
return;
} else {
console.warn(
["检查网盘中不存在此文件,重新上传文件:" , file , remotefile].join("\n")
["检查网盘中不存在此文件,重新上传文件:", file, remotefile].join(
"\n"
)
);
return await retryupload(file, destination);
}
Expand Down

0 comments on commit d229cd0

Please sign in to comment.