Skip to content

Commit

Permalink
修复bug和优化
Browse files Browse the repository at this point in the history
  • Loading branch information
masx200 committed Aug 9, 2020
1 parent 8b66021 commit 277e7f3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
14 changes: 9 additions & 5 deletions lib/uploadfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const fatalerror = [
const directfailure = [
"以下文件上传失败:",
"全部上传完毕, 总大小: 0B",
"ms, 总大小: 0B",
"打开上传未完成数据库错误:",
];
const retrymsg = [
Expand All @@ -29,17 +28,22 @@ export async function upload(file, destination) {
try {
result = await baidupcsupload(file, destination);
} catch (error) {
const { stdout, stderr } = error;
const { stdout, stderr, code } = error;
console.error(error);
console.error(JSON.stringify({ stdout, stderr }, null, 4));
if (typeof stdout !== "string" || typeof stderr !== "string") {
if (
typeof code !== "number" ||
typeof stdout !== "string" ||
typeof stderr !== "string"
) {
throw error;
} else if (
code === 2 &&
!directfailure.some((m) => stdout.includes(m)) &&
successerror.some((m) => stderr?.includes(m)) &&
successmsg.some((m) => stdout?.includes(m))
) {
console.log("文件上传成功", file, destination);
console.log("初步文件上传成功", file, destination);
return;
} else {
throw error;
Expand All @@ -55,7 +59,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);
console.log("初步文件上传成功", file, destination);
return;
} else if (retrymsg.some((msg) => stdout.includes(msg))) {
console.warn(stdout, stderr);
Expand Down
44 changes: 39 additions & 5 deletions lib/uploadfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ const directfailure = [
"以下文件上传失败:",

"全部上传完毕, 总大小: 0B",
"ms, 总大小: 0B",
// "ms, 总大小: 0B",
"打开上传未完成数据库错误:",
];
/*
[1] 加入上传队列: /sdcard/test/test/文件.txt
[1] 准备上传: /sdcard/test/test/文件.txt
[1] 目标文件, /我的测试/test/文件.txt, 已存在, 跳过...
上传结束, 时间: 547ms, 总大小: 0B
*/
const retrymsg = [
"网络错误, http 响应错误,",
"遇到错误, 远端服务器返回错误, 代码: 31352, 消息: commit superfile2 failed",
Expand Down Expand Up @@ -40,17 +48,43 @@ export async function upload(file: string, destination: string): Promise<void> {
try {
result = await baidupcsupload(file, destination);
} catch (error) {
const { stdout, stderr } = error;
const { stdout, stderr, code } = error;
console.error(error);
console.error(JSON.stringify({ stdout, stderr }, null, 4));
if (typeof stdout !== "string" || typeof stderr !== "string") {
/*
Error: spawn BaiduPCS-Go ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
at onErrorNT (internal/child_process.js:468:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn BaiduPCS-Go',
path: 'BaiduPCS-Go',
spawnargs: [ 'upload', '/sdcard/test/test/文件.txt', '/我 的测试/test' ],
cmd: 'BaiduPCS-Go upload /sdcard/test/test/文件.txt /我的 测试/test',
stdout: '',
stderr: ''
}
*/

/*
Error: Command failed: BaiduPCS-Go.exe upload D:\baidupandownload\微博美图合集-2020-02-15+2020-02-14\图片压缩输出\微博美图合集-2020-02-14\教主Shadow\微博配图\882ab48745b65338f17c993f80d3f15c.webp /我的图片/微博美图合集-2020-02-15+2020-02-14/图片压缩输出/微博美图合集-2020-02-14/教主Shadow/微博配图 panic: runtime error: index out of range goroutine 22 [running]:github.com/iikira/BaiduPCS-Go/internal/pcsfunctions/pcsupload.(*UploadingDatabase).UpdateUploading(0xc0422e48d0, 0xc042222240, 0xc0420f6ee0) /Users/syy/go/src/github.com/iikira/BaiduPCS-Go/internal/pcsfunctions/pcsupload/upload_database.go:101 +0x279github.com/iikira/BaiduPCS-Go/internal/pcscommand.RunUpload.func2.1(0xa60d20, 0xc042580a80, 0xc04205c240) /Users/syy/go/src/github.com/iikira/BaiduPCS-Go/internal/pcscommand/upload.go:355 +0x385github.com/iikira/BaiduPCS-Go/requester/uploader.(*MultiUploader).uploadStatusEvent.func1(0xc04206aa90) /Users/syy/go/src/github.com/iikira/BaiduPCS-Go/requester/uploader/status.go:93 +0x1a1created by github.com/iikira/BaiduPCS-Go/requester/uploader.(*MultiUploader).uploadStatusEvent /Users/syy/go/src/github.com/iikira/BaiduPCS-Go/requester/uploader/status.go:84 +0x4f at ChildProcess.exithandler (child_process.js:303:12) at ChildProcess.emit (events.js:321:20) at maybeClose (internal/child_process.js:1026:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) { killed: false, code: 2, signal: null, cmd: 'BaiduPCS-Go.exe upload D:\\baidupandownload\\微博美图合集-2020-02-15+2020-02-14\\图片压缩输出\\微博美图合集-2020-02-14\\教主Shadow\\微博配图\\882ab48745b65338f17c993f80d3f15c.webp /我的图片/微博美图合集-2020-02-15+2020-02-14/图片压缩输出/微博美图合集-2020-02-14/教主Shadow/微博配图',
*/
if (
typeof code !== "number" ||
typeof stdout !== "string" ||
typeof stderr !== "string"
) {
throw error;
} else if (
code === 2 &&
!directfailure.some((m) => stdout.includes(m)) &&
successerror.some((m) => stderr?.includes(m)) &&
successmsg.some((m) => stdout?.includes(m))
) {
console.log("文件上传成功", file, destination);
console.log("初步文件上传成功", file, destination);
return;
} else {
//如果。找不到 baidupcs-go的可执行文件,则。会在这里报错
Expand Down Expand Up @@ -79,7 +113,7 @@ export async function upload(file: string, destination: string): Promise<void> {
console.warn("上传失败,5秒后重试:" + file);
return await retryupload(file, destination);
} else if (successmsg.some((m) => stdout.includes(m))) {
console.log("文件上传成功", file, destination);
console.log("初步文件上传成功", file, destination);
return;
} else if (retrymsg.some((msg) => stdout.includes(msg))) {
console.warn(stdout, stderr);
Expand Down

0 comments on commit 277e7f3

Please sign in to comment.