tools_batch_files 1.0.25 → 1.0.26
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/package.json +1 -1
- package/src/photoBatch.js +21 -18
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";
|
@@ -59,7 +62,7 @@ function logFileSize(path) {
|
|
59
62
|
}
|
60
63
|
|
61
64
|
//普通日志
|
62
|
-
const logger = (log
|
65
|
+
const logger = (log) => {
|
63
66
|
console.log(log);
|
64
67
|
fs.writeFileSync("log.txt", log + "\n", {
|
65
68
|
flag: "a",
|
@@ -68,7 +71,7 @@ const logger = (log, hash, err) => {
|
|
68
71
|
|
69
72
|
//错误日志
|
70
73
|
const disposeError = (err) => {
|
71
|
-
logger("---任务失败---"
|
74
|
+
logger("---任务失败---" + err);
|
72
75
|
logger(
|
73
76
|
`******************************************************************end`
|
74
77
|
);
|
@@ -376,6 +379,16 @@ const postData = (dataParams, indexFilePath) => {
|
|
376
379
|
});
|
377
380
|
};
|
378
381
|
|
382
|
+
/**
|
383
|
+
* 上传失败后,存入新文件夹(手动创建)
|
384
|
+
*/
|
385
|
+
const moveFailFiles = (originFilePath, failPath) => {
|
386
|
+
if (originFilePath) {
|
387
|
+
fs.copyFileSync(originFilePath, failPath);
|
388
|
+
logger(`${originFilePath}上传失败,已移入错误文件夹!!!`);
|
389
|
+
}
|
390
|
+
};
|
391
|
+
|
379
392
|
/**
|
380
393
|
* 任务
|
381
394
|
*/
|
@@ -408,8 +421,7 @@ const task = async (row, index) => {
|
|
408
421
|
logger(`第${index}条Path路径搜索时间:${timeInSeconds}秒`);
|
409
422
|
logger(`-------------------${new Date()}------------------`);
|
410
423
|
|
411
|
-
|
412
|
-
console.log("fileName:" + fileName);
|
424
|
+
logger("originFilePath:" + originFilePath);
|
413
425
|
|
414
426
|
if (!originFilePath) {
|
415
427
|
logger(`图片文件 ${fileName} 不存在`);
|
@@ -453,7 +465,7 @@ const task = async (row, index) => {
|
|
453
465
|
if (resData.data.code === 200) {
|
454
466
|
logger("请求成功!");
|
455
467
|
logger(resData.data.code);
|
456
|
-
|
468
|
+
logger(resData.data);
|
457
469
|
//删除文件夹
|
458
470
|
fs.rmdirSync(indexFilePath, { recursive: true });
|
459
471
|
} else {
|
@@ -473,6 +485,10 @@ const task = async (row, index) => {
|
|
473
485
|
}
|
474
486
|
fs.rmdirSync(indexFilePath, { recursive: true });
|
475
487
|
disposeError(fileName);
|
488
|
+
|
489
|
+
//失败的时候,复制文件到错误文件夹中
|
490
|
+
const failPath = path.join(workDir, Error_Files_Dir, fileName);
|
491
|
+
moveFailFiles(originFilePath, failPath);
|
476
492
|
}
|
477
493
|
};
|
478
494
|
|
@@ -494,24 +510,11 @@ const transitionExcelToJSON = () => {
|
|
494
510
|
logger(
|
495
511
|
`run-------------------------------------第${index}条开始------------------------------------`
|
496
512
|
);
|
497
|
-
const readExcelStartTime = new Date();
|
498
513
|
const row = jsonData[index];
|
499
514
|
|
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
515
|
if (!row) {
|
509
516
|
return;
|
510
517
|
}
|
511
|
-
logger(
|
512
|
-
`----------------------------------------第${index}条task开始--------------------------------`
|
513
|
-
);
|
514
|
-
logger(`-------------------${new Date()}------------------`);
|
515
518
|
task(row, index)
|
516
519
|
.then(() => {
|
517
520
|
taskIndex++;
|