node-automator 1.4.2 → 1.4.4
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/commands/compress.js +27 -0
- package/commands/exec_from_file.js +6 -3
- package/commands/image_crop.js +8 -5
- package/commands/mgr.js +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { get_fst_file, get_full_path } = require('../utils/file_tool');
|
|
2
|
+
const { log, getPrint } = require('../utils/log_tool');
|
|
3
|
+
const { BaseCommand } = require("./base");
|
|
4
|
+
const sharp = require("sharp");
|
|
5
|
+
|
|
6
|
+
class CompressCommand extends BaseCommand {
|
|
7
|
+
async execute() {
|
|
8
|
+
const data = this.selfData;
|
|
9
|
+
const src = get_fst_file(data.src);
|
|
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);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
CompressCommand,
|
|
27
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { get_file_list, read_cfg, get_fst_file } = require("../utils/file_tool");
|
|
2
|
-
const { whisper, info, warn, success, vital, setLastExecFile } = require("../utils/log_tool");
|
|
2
|
+
const { whisper, info, warn, success, vital, setLastExecFile, getLastError } = require("../utils/log_tool");
|
|
3
3
|
const { parse } = require('../utils/parse_tool');
|
|
4
4
|
const { doRequest } = require('../utils/request_tool');
|
|
5
5
|
const { toArray } = require("../utils/transform_tool");
|
|
@@ -8,7 +8,6 @@ const { BaseCommand } = require("./base");
|
|
|
8
8
|
class ExecFromFileCommand extends BaseCommand {
|
|
9
9
|
async execute() {
|
|
10
10
|
let data = this.selfData;
|
|
11
|
-
let content = this.content;
|
|
12
11
|
let srcs = toArray(data.src);
|
|
13
12
|
for (let i = 0; i < srcs.length; i++) {
|
|
14
13
|
let src = srcs[i];
|
|
@@ -28,7 +27,11 @@ class ExecFromFileCommand extends BaseCommand {
|
|
|
28
27
|
setLastExecFile(src);
|
|
29
28
|
let cfg;
|
|
30
29
|
if (isRemote) {
|
|
31
|
-
|
|
30
|
+
let content = await doRequest({src, quiet: true});
|
|
31
|
+
if (getLastError()) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
cfg = await parse(content, "yml");
|
|
32
35
|
} else {
|
|
33
36
|
cfg = await read_cfg(src, data.type);
|
|
34
37
|
}
|
package/commands/image_crop.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
const { get_fst_file, get_full_path } = require('../utils/file_tool');
|
|
2
2
|
const { BaseCommand } = require("./base");
|
|
3
|
-
const
|
|
3
|
+
const sharp = require("sharp");
|
|
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);
|
|
10
9
|
const {x, y, w, h} = data.region;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
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);
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
|
package/commands/mgr.js
CHANGED
|
@@ -117,6 +117,7 @@ const { RegisterSearchInstallLocationCommand } = require('./register_search_inst
|
|
|
117
117
|
const { DeobfuscateCommand } = require('./deobfuscate');
|
|
118
118
|
const { AliOssCommand } = require('./ali_oss');
|
|
119
119
|
const { BackupCommand } = require('./backup');
|
|
120
|
+
const { CompressCommand } = require('./compress');
|
|
120
121
|
|
|
121
122
|
const globalData = {
|
|
122
123
|
"executed_cfg": [], // 执行过的配置文件
|
|
@@ -477,6 +478,7 @@ function init() {
|
|
|
477
478
|
register("deobfuscate", DeobfuscateCommand, false);
|
|
478
479
|
register("ali_oss", AliOssCommand, false);
|
|
479
480
|
register("backup", BackupCommand, false);
|
|
481
|
+
register("compress", CompressCommand, false);
|
|
480
482
|
}
|
|
481
483
|
|
|
482
484
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-automator",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Execute automation with yaml configuration(compatible with json)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,6 @@
|
|
|
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.10",
|
|
38
37
|
"json-stable-stringify": "^1.0.1",
|
|
39
38
|
"jwt-js": "^0.5.0",
|
|
40
39
|
"keypress": "^0.2.1",
|
|
@@ -50,6 +49,7 @@
|
|
|
50
49
|
"persist-path": "^1.0.2",
|
|
51
50
|
"request": "^2.88.2",
|
|
52
51
|
"request-progress": "^3.0.0",
|
|
52
|
+
"sharp": "^0.33.5",
|
|
53
53
|
"spreadsheet-column": "^1.1.1",
|
|
54
54
|
"strip-json-comments": "^3.1.1",
|
|
55
55
|
"temp": "^0.9.4",
|