tools_batch_files 1.0.17 → 1.0.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tools_batch_files",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
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 = 10;
38
+ const queueCount = 20;
39
39
 
40
40
  //起始任务下标
41
- let taskIndex = 0;
41
+ let taskIndex = 16941;
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,10 +327,12 @@ 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, {
331
+ return axios.post("http://127.0.0.1:9999/upload/photo", formData, {
320
332
  headers: {
321
333
  "Content-Type": "multipart/form-data",
322
334
  },
335
+ timeout: 600000, // 设置超时时间为 60 秒
323
336
  });
324
337
  };
325
338
 
@@ -379,9 +392,15 @@ const task = async (row, index) => {
379
392
  console.log(dataParams);
380
393
 
381
394
  const resData = await postData(dataParams, indexFilePath);
382
- logger(resData.data);
383
- //删除文件夹
384
- fs.rmdirSync(indexFilePath, { recursive: true });
395
+ if (resData.data.code === 200) {
396
+ logger("请求成功!");
397
+ logger(resData.data.code);
398
+ console.log(resData.data);
399
+ //删除文件夹
400
+ fs.rmdirSync(indexFilePath, { recursive: true });
401
+ } else {
402
+ throw new Error("请求失败!" + resData.data.msg);
403
+ }
385
404
 
386
405
  logger(
387
406
  `----------------------------------------第${index}条结束---------------------------------end`
@@ -394,7 +413,8 @@ const task = async (row, index) => {
394
413
  logger("图片任务处理失败:" + error);
395
414
  logger(error);
396
415
  }
397
- disposeError(hash, fileName);
416
+ fs.rmdirSync(indexFilePath, { recursive: true });
417
+ disposeError(fileName);
398
418
  }
399
419
  };
400
420
 
@@ -432,7 +452,7 @@ const transitionExcelToJSON = () => {
432
452
  };
433
453
 
434
454
  for (let i = 0; i < queueCount; i++) {
435
- run(i);
455
+ run(i + taskIndex);
436
456
  }
437
457
  };
438
458