tools_batch_files 1.0.16 → 1.0.18

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/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # 批量上传脚本
2
2
  ## 1.目录结构
3
- index.js 主函数
3
+ ├─ index.js 处理视频的主函数
4
+
4
5
  │ log.txt 日志
6
+
5
7
  │ 点我批量上传视频.bat 可执行文件
6
8
 
7
9
  ├─excel\excel.xlsx 表格文件
@@ -12,7 +14,7 @@
12
14
  ├─output 产物输出文件夹
13
15
 
14
16
  ├─src
15
- │ filterFail.js
17
+ │ filterFail.js 处理图片的函数
16
18
  │ index.js
17
19
 
18
20
  ├─utils 工具
@@ -27,9 +29,9 @@
27
29
  3. 全局安装包 tools_batch_files
28
30
  `npm i tools_batch_files -g`
29
31
  ### 启动脚本
30
- 1. 拖动.bat文件到需要处理的目录下 video/。
32
+ 1. 拖动.bat文件到需要处理的目录下(图片或视频)。
31
33
  2. 确保excel文件存在
32
- 3. 点击“点我批量上传视频.bat”开始脚本
34
+ 3. 点击“点我批量上传xx.bat”开始脚本
33
35
  4. error.txt和log.txt-----错误日志和普通日志。
34
36
 
35
37
  ### 功能
@@ -40,6 +42,8 @@
40
42
  4. 5截图(水印)
41
43
  5. 打包
42
44
 
45
+ #### 2. 批量处理图片
46
+ 1. 生成预览图 1280
47
+ 2. 生成水印预览图
43
48
  ## 3.下个版本的优化点
44
- - 尝试在内存中处理 stream
45
- - 上传成功后删除相关文件
49
+ - 尝试在内存中处理 stream
package/index.js CHANGED
@@ -30,7 +30,7 @@ const SOURCE_VIDEO_DIR = "source_video";
30
30
  const ZIP_FILES_DIR = "zip";
31
31
 
32
32
  //并发数量
33
- const queueCount = 1;
33
+ const queueCount = 10;
34
34
 
35
35
  //起始任务下标
36
36
  let taskIndex = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tools_batch_files",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "批处理视频工具",
5
5
  "keywords": [
6
6
  "utils",
package/src/photoBatch.js CHANGED
@@ -35,10 +35,10 @@ const ZIP_FILES_DIR = "zip";
35
35
  const expandedName = ".jpg";
36
36
 
37
37
  //并发数量
38
- const queueCount = 1;
38
+ const queueCount = 30;
39
39
 
40
40
  //起始任务下标
41
- let taskIndex = 0;
41
+ let taskIndex = 16492;
42
42
 
43
43
  const readExcel = (path) => {
44
44
  const workbook = XLSX.readFile(path);
@@ -66,6 +66,17 @@ const logger = (log, hash, err) => {
66
66
  });
67
67
  };
68
68
 
69
+ //错误日志
70
+ const disposeError = (err) => {
71
+ logger("---任务失败---", err);
72
+ logger(
73
+ `******************************************************************end`
74
+ );
75
+ fs.writeFileSync("error.txt", err + "\n", {
76
+ flag: "a",
77
+ });
78
+ };
79
+
69
80
  /**
70
81
  * 递归遍历文件夹,查找文件
71
82
  * @param {*} dir 文件夹路径
@@ -316,7 +327,7 @@ const postData = (dataParams, indexFilePath) => {
316
327
 
317
328
  logger("等待接口返回结果……");
318
329
 
319
- return axios.post("http://192.168.101.149:9999/upload/photo", formData, {
330
+ return axios.post("http://192.168.102.61:9999/upload/photo", formData, {
320
331
  headers: {
321
332
  "Content-Type": "multipart/form-data",
322
333
  },
@@ -379,9 +390,15 @@ const task = async (row, index) => {
379
390
  console.log(dataParams);
380
391
 
381
392
  const resData = await postData(dataParams, indexFilePath);
382
- logger(resData.data);
383
- //删除文件夹
384
- fs.rmdirSync(indexFilePath, { recursive: true });
393
+ if (resData.data.code === 200) {
394
+ logger("请求成功!");
395
+ logger(resData.data.code);
396
+ console.log(resData.data);
397
+ //删除文件夹
398
+ fs.rmdirSync(indexFilePath, { recursive: true });
399
+ } else {
400
+ throw new Error("请求失败!" + resData.data.msg);
401
+ }
385
402
 
386
403
  logger(
387
404
  `----------------------------------------第${index}条结束---------------------------------end`
@@ -394,7 +411,8 @@ const task = async (row, index) => {
394
411
  logger("图片任务处理失败:" + error);
395
412
  logger(error);
396
413
  }
397
- disposeError(hash, fileName);
414
+ fs.rmdirSync(indexFilePath, { recursive: true });
415
+ disposeError(fileName);
398
416
  }
399
417
  };
400
418
 
@@ -432,7 +450,7 @@ const transitionExcelToJSON = () => {
432
450
  };
433
451
 
434
452
  for (let i = 0; i < queueCount; i++) {
435
- run(i);
453
+ run(i + taskIndex);
436
454
  }
437
455
  };
438
456