tools_batch_files 1.0.24 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tools_batch_files",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "批处理视频工具",
5
5
  "keywords": [
6
6
  "utils",
@@ -12,7 +12,8 @@
12
12
  "bin": {
13
13
  "tbf": "./index.js",
14
14
  "tbfp": "./src/photoBatch.js",
15
- "tbfb": "./src/photoBatchBack.js"
15
+ "tbfb": "./src/photoBatchBack.js",
16
+ "tbfre": "./src/removeFailVideo.js"
16
17
  },
17
18
  "scripts": {
18
19
  "test": "echo \"Error: no test specified\" && exit 1",
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, hash, err) => {
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("---任务失败---", err);
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
- console.log("originFilePath:" + originFilePath);
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
- console.log(resData.data);
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++;
@@ -3,13 +3,13 @@ const path = require("path");
3
3
 
4
4
  const workDir = process.cwd();
5
5
 
6
- const ORIGIN_FILE_DIR = "video";
6
+ const ORIGIN_FILE_DIR = "photos";
7
7
 
8
8
  // error错误日志目录
9
9
  const errorDir = path.join(workDir, "error.txt");
10
10
 
11
- const Error_Files_Dir = "failed_videos";
12
- // const Error_Files_Dir = "failed_photos";
11
+ // const Error_Files_Dir = "failed_videos";
12
+ const Error_Files_Dir = "failed_photos";
13
13
 
14
14
  /**
15
15
  * 确保目录存在,如果不存在则创建它
@@ -61,7 +61,8 @@ function findFileInDir(dir, fileName) {
61
61
  if (result) {
62
62
  return result;
63
63
  }
64
- } else if (file.startsWith(fileName) && file.endsWith(".mov")) {
64
+ // } else if (file.startsWith(fileName) && file.endsWith(".mov")) {
65
+ } else if (file.startsWith(fileName) && file.endsWith(".jpg")) {
65
66
  return { filePath, file };
66
67
  }
67
68
  }
@@ -90,7 +91,8 @@ txtData.forEach((item, index) => {
90
91
  const { filePath: originFilePath, file: fileName } = fileObj;
91
92
 
92
93
  if (originFilePath) {
93
- const failPath = path.join(workDir, Error_Files_Dir, fileName);
94
+ // const failPath = path.join(workDir, Error_Files_Dir, fileName);
95
+ const failPath = path.join("E:", Error_Files_Dir, fileName);
94
96
  // ensureDirSync(failPath)
95
97
 
96
98
  fs.copyFileSync(originFilePath, failPath);