node-automator 1.4.4 → 1.4.6

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.
@@ -7,7 +7,8 @@ const fs = require("fs");
7
7
  const path = require("path");
8
8
  const {
9
9
  success,
10
- error
10
+ error,
11
+ warn
11
12
  } = require('../utils/log_tool');
12
13
  const {
13
14
  parse,
@@ -50,6 +51,10 @@ class BackupCommand extends BaseCommand {
50
51
  backupData = backupData[key];
51
52
  }
52
53
  }
54
+ if (backupData === undefined) {
55
+ warn(`未找到 ${filename} 的 ${sourceKeys} 字段`)
56
+ return;
57
+ }
53
58
  if (backupFormat) {
54
59
  backupData = await stringify(backupData, backupFormat);
55
60
  }
@@ -1,24 +1,17 @@
1
1
  const { get_fst_file, get_full_path } = require('../utils/file_tool');
2
2
  const { log, getPrint } = require('../utils/log_tool');
3
3
  const { BaseCommand } = require("./base");
4
- const sharp = require("sharp");
4
+ const Jimp = require("jimp");
5
5
 
6
6
  class CompressCommand extends BaseCommand {
7
7
  async execute() {
8
8
  const data = this.selfData;
9
9
  const src = get_fst_file(data.src);
10
10
  const dst = get_full_path(data.dst, "FILE");
11
- let format = data.format;
12
- if (!format) {
13
- format = dst.split(".").pop();
14
- }
15
- format = format.toLowerCase();
16
- if (format === "jpg") {
17
- format = "jpeg";
18
- }
19
- const options = data.options;
20
- await sharp(src)[format](options)
21
- .toFile(dst);
11
+ const options = data.options || {};
12
+ let image = await Jimp.read(src);
13
+ image.quality(options.quality || 80);
14
+ await image.writeAsync(dst);
22
15
  }
23
16
  }
24
17
 
@@ -1,19 +1,16 @@
1
1
  const { get_fst_file, get_full_path } = require('../utils/file_tool');
2
2
  const { BaseCommand } = require("./base");
3
- const sharp = require("sharp");
3
+ const Jimp = require("jimp");
4
4
 
5
5
  class ImageCropCommand extends BaseCommand {
6
6
  async execute() {
7
7
  const data = this.selfData;
8
8
  const src = get_fst_file(data.src);
9
+ const image = await Jimp.read(src);
9
10
  const {x, y, w, h} = data.region;
10
- const dst = get_full_path(data.dst, "FILE");
11
- await sharp(src).extract({
12
- left: x,
13
- top: y,
14
- width: w,
15
- height: h,
16
- }).toFile(dst);
11
+ const croped = image.crop(x, y, w, h);
12
+ const dst = get_full_path(data.dst);
13
+ await croped.writeAsync(dst);
17
14
  }
18
15
  }
19
16
 
package/commands/mgr.js CHANGED
@@ -118,6 +118,7 @@ const { DeobfuscateCommand } = require('./deobfuscate');
118
118
  const { AliOssCommand } = require('./ali_oss');
119
119
  const { BackupCommand } = require('./backup');
120
120
  const { CompressCommand } = require('./compress');
121
+ const { Word2txtCommand } = require('./word2txt');
121
122
 
122
123
  const globalData = {
123
124
  "executed_cfg": [], // 执行过的配置文件
@@ -479,6 +480,7 @@ function init() {
479
480
  register("ali_oss", AliOssCommand, false);
480
481
  register("backup", BackupCommand, false);
481
482
  register("compress", CompressCommand, false);
483
+ register("word2txt", Word2txtCommand, false);
482
484
  }
483
485
 
484
486
  module.exports = {
@@ -0,0 +1,42 @@
1
+ const {
2
+ get_fst_file
3
+ } = require('../utils/file_tool');
4
+ const {
5
+ BaseCommand
6
+ } = require("./base");
7
+ const fs = require('fs');
8
+ const mammoth = require('mammoth');
9
+
10
+ class Word2txtCommand extends BaseCommand {
11
+ async execute() {
12
+ const data = this.selfData;
13
+ const wordFilePath = get_fst_file(data.src);
14
+ return new Promise((resolve, reject) => {
15
+ // 读取 Word 文件
16
+ fs.readFile(wordFilePath, (err, data) => {
17
+ if (err) {
18
+ reject(err);
19
+ return console.error("读取文件时出错:", err);
20
+ }
21
+
22
+ // 将 Word 文件转换为纯文本
23
+ mammoth.extractRawText({
24
+ buffer: data
25
+ })
26
+ .then((result) => {
27
+ const text = result.value; // 纯文本内容
28
+ console.log("转换后的文本内容:", text);
29
+ resolve(text);
30
+ })
31
+ .catch((err) => {
32
+ console.error("转换过程中出错:", err);
33
+ reject(err);
34
+ });
35
+ });
36
+ })
37
+ }
38
+ }
39
+
40
+ module.exports = {
41
+ Word2txtCommand,
42
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-automator",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "Execute automation with yaml configuration(compatible with json)",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -34,12 +34,14 @@
34
34
  "html-to-text": "^8.2.0",
35
35
  "iconv-lite": "^0.6.2",
36
36
  "image-size": "^1.0.0",
37
+ "jimp": "^0.22.12",
37
38
  "json-stable-stringify": "^1.0.1",
38
39
  "jwt-js": "^0.5.0",
39
40
  "keypress": "^0.2.1",
40
41
  "log4js": "^6.3.0",
41
42
  "luaparse": "^0.3.1",
42
43
  "mail-watcher": "^0.6.1",
44
+ "mammoth": "^1.8.0",
43
45
  "markdown-table": "^2.0.0",
44
46
  "mysql": "^2.18.1",
45
47
  "node-localstorage": "^2.1.6",
@@ -49,7 +51,6 @@
49
51
  "persist-path": "^1.0.2",
50
52
  "request": "^2.88.2",
51
53
  "request-progress": "^3.0.0",
52
- "sharp": "^0.33.5",
53
54
  "spreadsheet-column": "^1.1.1",
54
55
  "strip-json-comments": "^3.1.1",
55
56
  "temp": "^0.9.4",
@@ -64,6 +64,7 @@ async function exec_shell(data) {
64
64
  let results = [];
65
65
  let errors = [];
66
66
  let encoding = data.encoding || "cp936";
67
+ let raw_output = encoding == "raw";
67
68
  !quiet && whisper(`cmd:[${cmd}] cwd:${data.cwd} inputs:${data.inputs}`);
68
69
  options.stdio = ["pipe", capture_stdout ? "pipe" : process.stdout, "pipe"];
69
70
  const child = child_process.spawn(cmd[0], cmd.slice(1), options);
@@ -71,7 +72,7 @@ async function exec_shell(data) {
71
72
  child.stdout.on("data", (chunk) => {
72
73
  results.push(chunk);
73
74
  if (instant_stdout) {
74
- warn(iconv.decode(chunk, encoding));
75
+ warn(!raw_output ? iconv.decode(chunk, encoding) : chunk.toString());
75
76
  }
76
77
  });
77
78
  }
@@ -98,7 +99,7 @@ async function exec_shell(data) {
98
99
  // child.on('close', code => {
99
100
  child.on('exit', code => {
100
101
  if (!data.ignore_code && code != 0) {
101
- let errMsg = iconv.decode(Buffer.concat(errors), encoding);
102
+ let errMsg = !raw_output ? iconv.decode(Buffer.concat(errors), encoding) : Buffer.concat(errors).toString();
102
103
  let isAcceptableErrors = errMsg && acceptableErrors.some(err => {
103
104
  return errMsg.indexOf(err) >= 0;
104
105
  });
@@ -107,7 +108,7 @@ async function exec_shell(data) {
107
108
  }
108
109
  }
109
110
  if (results.length) {
110
- let result = iconv.decode(Buffer.concat(results), encoding);
111
+ let result = !raw_output ? iconv.decode(Buffer.concat(results), encoding) : Buffer.concat(results);
111
112
  if (data.trim) {
112
113
  result = result.trim();
113
114
  }