tools_batch_files 1.0.25 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -2
- package/package.json +1 -1
- package/src/photoBatch.js +32 -20
package/index.js
CHANGED
@@ -555,7 +555,7 @@ const task = async (row, index) => {
|
|
555
555
|
logger(resData.data.code);
|
556
556
|
logger(resData.data);
|
557
557
|
//删除文件夹
|
558
|
-
|
558
|
+
fs.rmdirSync(indexFilePath, { recursive: true });
|
559
559
|
} else {
|
560
560
|
throw new Error("请求失败!" + resData.data.msg);
|
561
561
|
}
|
@@ -573,7 +573,7 @@ const task = async (row, index) => {
|
|
573
573
|
}
|
574
574
|
logger("catch日志*********************************");
|
575
575
|
disposeError(fileName);
|
576
|
-
|
576
|
+
fs.rmdirSync(indexFilePath, { recursive: true });
|
577
577
|
}
|
578
578
|
};
|
579
579
|
|
package/package.json
CHANGED
package/src/photoBatch.js
CHANGED
@@ -19,6 +19,9 @@ const excelDir = path.join(workDir, "excel", "excel.xlsx");
|
|
19
19
|
//水印
|
20
20
|
const watermarkImage = path.join(__dirname, "..", "imgs", "picWater.png");
|
21
21
|
|
22
|
+
//拷贝 - 存放上传失败的文件
|
23
|
+
const Error_Files_Dir = "failed_photos";
|
24
|
+
|
22
25
|
// 截图数量
|
23
26
|
const SCREENSHOT_COUNT = 5;
|
24
27
|
const ORIGIN_FILE_DIR = "photos";
|
@@ -38,7 +41,13 @@ const expandedName = ".jpg";
|
|
38
41
|
const queueCount = 50;
|
39
42
|
|
40
43
|
//起始任务下标
|
41
|
-
let taskIndex =
|
44
|
+
let taskIndex = 0;
|
45
|
+
|
46
|
+
//重传的 上传进度
|
47
|
+
const progressIndex = 0;
|
48
|
+
|
49
|
+
//重传的总数
|
50
|
+
const totals = 11874;
|
42
51
|
|
43
52
|
const readExcel = (path) => {
|
44
53
|
const workbook = XLSX.readFile(path);
|
@@ -59,7 +68,7 @@ function logFileSize(path) {
|
|
59
68
|
}
|
60
69
|
|
61
70
|
//普通日志
|
62
|
-
const logger = (log
|
71
|
+
const logger = (log) => {
|
63
72
|
console.log(log);
|
64
73
|
fs.writeFileSync("log.txt", log + "\n", {
|
65
74
|
flag: "a",
|
@@ -68,7 +77,7 @@ const logger = (log, hash, err) => {
|
|
68
77
|
|
69
78
|
//错误日志
|
70
79
|
const disposeError = (err) => {
|
71
|
-
logger("---任务失败---"
|
80
|
+
logger("---任务失败---" + err);
|
72
81
|
logger(
|
73
82
|
`******************************************************************end`
|
74
83
|
);
|
@@ -376,6 +385,16 @@ const postData = (dataParams, indexFilePath) => {
|
|
376
385
|
});
|
377
386
|
};
|
378
387
|
|
388
|
+
/**
|
389
|
+
* 上传失败后,存入新文件夹(手动创建)
|
390
|
+
*/
|
391
|
+
const moveFailFiles = (originFilePath, failPath) => {
|
392
|
+
if (originFilePath) {
|
393
|
+
fs.copyFileSync(originFilePath, failPath);
|
394
|
+
logger(`${originFilePath}上传失败,已移入错误文件夹!!!`);
|
395
|
+
}
|
396
|
+
};
|
397
|
+
|
379
398
|
/**
|
380
399
|
* 任务
|
381
400
|
*/
|
@@ -408,8 +427,7 @@ const task = async (row, index) => {
|
|
408
427
|
logger(`第${index}条Path路径搜索时间:${timeInSeconds}秒`);
|
409
428
|
logger(`-------------------${new Date()}------------------`);
|
410
429
|
|
411
|
-
|
412
|
-
console.log("fileName:" + fileName);
|
430
|
+
logger("originFilePath:" + originFilePath);
|
413
431
|
|
414
432
|
if (!originFilePath) {
|
415
433
|
logger(`图片文件 ${fileName} 不存在`);
|
@@ -451,9 +469,12 @@ const task = async (row, index) => {
|
|
451
469
|
logger(`-------------------${new Date()}------------------`);
|
452
470
|
|
453
471
|
if (resData.data.code === 200) {
|
472
|
+
progressIndex++;
|
454
473
|
logger("请求成功!");
|
455
|
-
logger(resData.data
|
456
|
-
|
474
|
+
logger(resData.data);
|
475
|
+
if(totals) {
|
476
|
+
logger(`任务进度:${progressIndex}/${totals}`);
|
477
|
+
}
|
457
478
|
//删除文件夹
|
458
479
|
fs.rmdirSync(indexFilePath, { recursive: true });
|
459
480
|
} else {
|
@@ -473,6 +494,10 @@ const task = async (row, index) => {
|
|
473
494
|
}
|
474
495
|
fs.rmdirSync(indexFilePath, { recursive: true });
|
475
496
|
disposeError(fileName);
|
497
|
+
|
498
|
+
//失败的时候,复制文件到错误文件夹中
|
499
|
+
const failPath = path.join(workDir, Error_Files_Dir, fileName);
|
500
|
+
moveFailFiles(originFilePath, failPath);
|
476
501
|
}
|
477
502
|
};
|
478
503
|
|
@@ -494,24 +519,11 @@ const transitionExcelToJSON = () => {
|
|
494
519
|
logger(
|
495
520
|
`run-------------------------------------第${index}条开始------------------------------------`
|
496
521
|
);
|
497
|
-
const readExcelStartTime = new Date();
|
498
522
|
const row = jsonData[index];
|
499
523
|
|
500
|
-
const readExcelEndTime = new Date();
|
501
|
-
const timeInSeconds = (
|
502
|
-
(readExcelEndTime - readExcelStartTime) /
|
503
|
-
1000
|
504
|
-
).toFixed(2);
|
505
|
-
|
506
|
-
logger(`第${index}条Excel搜索时间:${timeInSeconds}秒`);
|
507
|
-
logger(`-------------------${new Date()}------------------`);
|
508
524
|
if (!row) {
|
509
525
|
return;
|
510
526
|
}
|
511
|
-
logger(
|
512
|
-
`----------------------------------------第${index}条task开始--------------------------------`
|
513
|
-
);
|
514
|
-
logger(`-------------------${new Date()}------------------`);
|
515
527
|
task(row, index)
|
516
528
|
.then(() => {
|
517
529
|
taskIndex++;
|