node-automator 1.4.25 → 1.4.27

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.
Files changed (179) hide show
  1. package/biome.json +63 -0
  2. package/commands/abort.js +11 -11
  3. package/commands/alert.js +17 -19
  4. package/commands/ali_oss.js +214 -151
  5. package/commands/assemble.js +54 -56
  6. package/commands/assert.js +18 -18
  7. package/commands/backup.js +52 -48
  8. package/commands/base.js +390 -363
  9. package/commands/break.js +11 -11
  10. package/commands/change_filter.js +34 -34
  11. package/commands/cheerio.js +15 -15
  12. package/commands/clear_screen.js +14 -14
  13. package/commands/commit.js +29 -31
  14. package/commands/compare.js +4 -4
  15. package/commands/compress.js +30 -17
  16. package/commands/confirm.js +16 -16
  17. package/commands/continue.js +11 -11
  18. package/commands/copy.js +14 -14
  19. package/commands/cursor_up.js +12 -12
  20. package/commands/date.js +25 -25
  21. package/commands/debugger.js +9 -11
  22. package/commands/deobfuscate.js +19 -15
  23. package/commands/dingtalk.js +110 -110
  24. package/commands/disassemble.js +32 -36
  25. package/commands/divination.js +18 -15
  26. package/commands/download.js +12 -12
  27. package/commands/edit.js +85 -83
  28. package/commands/edit_excel.js +55 -57
  29. package/commands/env_optional.js +57 -57
  30. package/commands/eval.js +20 -27
  31. package/commands/exec_from_file.js +53 -45
  32. package/commands/export_diff_head.js +29 -31
  33. package/commands/file_info.js +39 -41
  34. package/commands/file_size.js +12 -12
  35. package/commands/files.js +19 -14
  36. package/commands/first_exist.js +18 -18
  37. package/commands/flatten.js +18 -18
  38. package/commands/ftp.js +179 -161
  39. package/commands/git_commit.js +35 -31
  40. package/commands/git_export_diff_head.js +13 -13
  41. package/commands/git_is_dirty.js +13 -13
  42. package/commands/hash.js +25 -21
  43. package/commands/http_request.js +12 -12
  44. package/commands/image_crop.js +3 -3
  45. package/commands/input.js +35 -37
  46. package/commands/interval.js +76 -60
  47. package/commands/is_dirty.js +29 -31
  48. package/commands/jwt_decode.js +22 -22
  49. package/commands/list2dict.js +38 -32
  50. package/commands/log.js +72 -72
  51. package/commands/loop.js +127 -115
  52. package/commands/loop_forever.js +77 -66
  53. package/commands/merge_file.js +26 -25
  54. package/commands/merge_files.js +43 -39
  55. package/commands/mgr.js +530 -498
  56. package/commands/modify.js +42 -44
  57. package/commands/move.js +14 -14
  58. package/commands/move_local.js +14 -14
  59. package/commands/multi_select.js +16 -16
  60. package/commands/mysql_connect.js +29 -29
  61. package/commands/mysql_end.js +13 -13
  62. package/commands/mysql_query.js +17 -19
  63. package/commands/notify.js +13 -13
  64. package/commands/obfuscate.js +55 -59
  65. package/commands/open.js +29 -30
  66. package/commands/parse.js +18 -18
  67. package/commands/pause.js +15 -15
  68. package/commands/print.js +74 -47
  69. package/commands/read_cache.js +16 -12
  70. package/commands/read_cfg.js +13 -13
  71. package/commands/read_clipboard.js +19 -19
  72. package/commands/read_excel.js +17 -17
  73. package/commands/read_only_excel.js +40 -40
  74. package/commands/read_plain.js +14 -14
  75. package/commands/register_search_install_location.js +2 -2
  76. package/commands/remove.js +14 -14
  77. package/commands/retrieve.js +17 -17
  78. package/commands/reveal.js +33 -33
  79. package/commands/revision_info.js +45 -31
  80. package/commands/schedule.js +90 -80
  81. package/commands/select.js +16 -17
  82. package/commands/send_email.js +25 -25
  83. package/commands/share_data.js +797 -757
  84. package/commands/shell.js +13 -13
  85. package/commands/sleep.js +17 -17
  86. package/commands/split_file.js +41 -39
  87. package/commands/store.js +13 -13
  88. package/commands/store_optional.js +37 -33
  89. package/commands/stream.js +16 -16
  90. package/commands/stringify.js +22 -24
  91. package/commands/svn_add.js +20 -17
  92. package/commands/svn_commit.js +54 -49
  93. package/commands/svn_export_diff_head.js +13 -13
  94. package/commands/svn_is_dirty.js +13 -13
  95. package/commands/svn_update.js +27 -27
  96. package/commands/switch.js +18 -18
  97. package/commands/temp.js +12 -12
  98. package/commands/tencent_cos.js +386 -323
  99. package/commands/test.js +14 -14
  100. package/commands/title.js +21 -21
  101. package/commands/tmpdir.js +18 -21
  102. package/commands/translate.js +61 -58
  103. package/commands/traversal.js +39 -38
  104. package/commands/truncate.js +29 -31
  105. package/commands/truncate_all.js +60 -62
  106. package/commands/ts_sort.js +18 -18
  107. package/commands/unzip.js +55 -50
  108. package/commands/updating_revision.js +30 -28
  109. package/commands/valid_required.js +39 -31
  110. package/commands/void.js +9 -10
  111. package/commands/watch_mail.js +95 -94
  112. package/commands/web_socket.js +271 -233
  113. package/commands/which.js +18 -19
  114. package/commands/word2txt.js +9 -12
  115. package/commands/write_cache.js +21 -16
  116. package/commands/write_cfg.js +18 -18
  117. package/commands/write_clipboard.js +26 -23
  118. package/commands/write_excel.js +17 -17
  119. package/commands/write_plain.js +18 -18
  120. package/commands/zip.js +88 -78
  121. package/commands/zip_data.js +69 -64
  122. package/commands/zip_folder.js +61 -56
  123. package/index.js +193 -152
  124. package/package.json +78 -72
  125. package/utils/alert_tool.js +131 -133
  126. package/utils/base64_tool.js +12 -12
  127. package/utils/cache/local_cache.js +91 -79
  128. package/utils/cache/raw_cache.js +48 -47
  129. package/utils/cache/simple_local_cache.js +44 -33
  130. package/utils/cache/simple_sqlite_cache.js +54 -43
  131. package/utils/cache/simple_svn_cache.js +55 -49
  132. package/utils/cache/svn_cache.js +40 -40
  133. package/utils/cache_tool.js +53 -53
  134. package/utils/deobfuscator/deobfuscator.js +26 -13
  135. package/utils/deobfuscator/helpers/declaration.js +66 -38
  136. package/utils/deobfuscator/helpers/expression.js +49 -25
  137. package/utils/deobfuscator/helpers/misc.js +6 -8
  138. package/utils/deobfuscator/helpers/strings/decoders/base64StringDecoder.js +0 -1
  139. package/utils/deobfuscator/helpers/strings/decoders/basicStringDecoder.js +0 -1
  140. package/utils/deobfuscator/helpers/strings/decoders/rc4StringDecoder.js +4 -3
  141. package/utils/deobfuscator/helpers/strings/decoders/stringDecoder.js +4 -5
  142. package/utils/deobfuscator/helpers/strings/rotation/rotation.js +109 -75
  143. package/utils/deobfuscator/helpers/strings/util/util.js +8 -8
  144. package/utils/deobfuscator/helpers/variable.js +89 -43
  145. package/utils/deobfuscator/index.js +15 -11
  146. package/utils/deobfuscator/transformations/config.js +13 -14
  147. package/utils/deobfuscator/transformations/controlFlow/controlFlowRecoverer.js +126 -60
  148. package/utils/deobfuscator/transformations/controlFlow/deadBranchRemover.js +91 -53
  149. package/utils/deobfuscator/transformations/controlFlow/sequenceSplitter.js +128 -72
  150. package/utils/deobfuscator/transformations/expressions/expressionSimplifier.js +170 -125
  151. package/utils/deobfuscator/transformations/objects/objectPacker.js +101 -51
  152. package/utils/deobfuscator/transformations/objects/objectSimplifier.js +26 -15
  153. package/utils/deobfuscator/transformations/objects/proxyObject.js +93 -48
  154. package/utils/deobfuscator/transformations/properties/propertySimplifier.js +63 -37
  155. package/utils/deobfuscator/transformations/proxyFunctions/proxyFunction.js +81 -47
  156. package/utils/deobfuscator/transformations/proxyFunctions/proxyFunctionInliner.js +24 -13
  157. package/utils/deobfuscator/transformations/strings/stringRevealer.js +351 -197
  158. package/utils/deobfuscator/transformations/transformation.js +1 -2
  159. package/utils/deobfuscator/transformations/variables/constantPropagator.js +62 -36
  160. package/utils/deobfuscator/transformations/variables/reassignmentRemover.js +66 -40
  161. package/utils/deobfuscator/transformations/variables/unusedVariableRemover.js +82 -53
  162. package/utils/display_tool.js +107 -86
  163. package/utils/divination_util.js +564 -555
  164. package/utils/file_tool.js +595 -533
  165. package/utils/func_tool.js +32 -30
  166. package/utils/hash_tool.js +4 -4
  167. package/utils/interaction_tool.js +257 -227
  168. package/utils/log_tool.js +227 -215
  169. package/utils/parse_directive.js +189 -194
  170. package/utils/parse_tool.js +245 -236
  171. package/utils/reg_tool.js +35 -35
  172. package/utils/request_tool.js +169 -148
  173. package/utils/scm_tool.js +137 -108
  174. package/utils/selection_tool.js +610 -573
  175. package/utils/shell_tool.js +173 -164
  176. package/utils/svn_diff/diff_file.js +36 -38
  177. package/utils/svn_diff/diff_parser.js +51 -52
  178. package/utils/transform_tool.js +562 -537
  179. package/utils/which_tool.js +43 -43
package/biome.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
3
+ "vcs": {
4
+ "enabled": false,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": false
7
+ },
8
+ "files": {
9
+ "ignoreUnknown": false
10
+ },
11
+ "formatter": {
12
+ "enabled": true,
13
+ "indentStyle": "space",
14
+ "indentWidth": 4
15
+ },
16
+ "linter": {
17
+ "enabled": true,
18
+ "rules": {
19
+ "recommended": true,
20
+ "complexity": {
21
+ "noStaticOnlyClass": "off"
22
+ },
23
+ "suspicious": {
24
+ "noDuplicateClassMembers": "warn",
25
+ "useIterableCallbackReturn": "warn",
26
+ "noCompareNegZero": "warn",
27
+ "noDuplicateElseIf": "warn",
28
+ "noSelfCompare": "warn",
29
+ "noFallthroughSwitchClause": "warn",
30
+ "noDebugger": "warn",
31
+ "noShadowRestrictedNames": "warn",
32
+ "noImplicitAnyLet": "warn",
33
+ "noAssignInExpressions": "warn",
34
+ "noEmptyInterface": "off",
35
+ "noDuplicateObjectKeys": "warn",
36
+ "noDoubleEquals": "warn",
37
+ "noRedeclare": "warn"
38
+ },
39
+ "correctness": {
40
+ "noPrecisionLoss": "warn",
41
+ "noSwitchDeclarations": "warn",
42
+ "noConstantCondition": "warn",
43
+ "noUnreachable": "warn",
44
+ "noInvalidUseBeforeDeclaration": "warn",
45
+ "noInnerDeclarations": "warn",
46
+ "noSelfAssign": "warn"
47
+ }
48
+ }
49
+ },
50
+ "javascript": {
51
+ "formatter": {
52
+ "quoteStyle": "double"
53
+ }
54
+ },
55
+ "assist": {
56
+ "enabled": true,
57
+ "actions": {
58
+ "source": {
59
+ "organizeImports": "on"
60
+ }
61
+ }
62
+ }
63
+ }
package/commands/abort.js CHANGED
@@ -1,11 +1,11 @@
1
- const { BaseCommand } = require("./base");
2
-
3
- class AbortCommand extends BaseCommand {
4
- async execute() {
5
- throw (this.selfData && this.selfData.prompt) || "任务中止";
6
- }
7
- }
8
-
9
- module.exports = {
10
- AbortCommand,
11
- };
1
+ const { BaseCommand } = require("./base");
2
+
3
+ class AbortCommand extends BaseCommand {
4
+ async execute() {
5
+ throw this.selfData?.prompt || "任务中止";
6
+ }
7
+ }
8
+
9
+ module.exports = {
10
+ AbortCommand,
11
+ };
package/commands/alert.js CHANGED
@@ -1,19 +1,17 @@
1
- const { showAlert } = require("../utils/alert_tool");
2
- const { BaseCommand } = require("./base");
3
-
4
- class AlertCommand extends BaseCommand {
5
- async execute() {
6
- let data = this.selfData;
7
- await showAlert(data.type, data.msg, data.title);
8
- }
9
-
10
- getRequiredParams() {
11
- return [
12
- "msg",
13
- ];
14
- }
15
- }
16
-
17
- module.exports = {
18
- AlertCommand,
19
- };
1
+ const { showAlert } = require("../utils/alert_tool");
2
+ const { BaseCommand } = require("./base");
3
+
4
+ class AlertCommand extends BaseCommand {
5
+ async execute() {
6
+ const data = this.selfData;
7
+ await showAlert(data.type, data.msg, data.title);
8
+ }
9
+
10
+ getRequiredParams() {
11
+ return ["msg"];
12
+ }
13
+ }
14
+
15
+ module.exports = {
16
+ AlertCommand,
17
+ };
@@ -1,41 +1,24 @@
1
1
  const {
2
2
  get_file_list,
3
3
  get_full_path,
4
- format_bytes
4
+ format_bytes,
5
5
  } = require("../utils/file_tool");
6
- const {
7
- success,
8
- getPrint,
9
- info,
10
- warn,
11
- whisper
12
- } = require("../utils/log_tool");
13
- const {
14
- BaseCommand
15
- } = require("./base");
16
- const path = require("path");
17
- const {
18
- progress
19
- } = require("../utils/display_tool");
20
- const {
21
- createWriteStream, readFileSync
22
- } = require("fs");
23
- const {
24
- getCache,
25
- setCache
26
- } = require("../utils/cache_tool");
27
- const crypto = require("crypto");
28
- const { queueAsync } = require('../utils/func_tool');
29
-
6
+ const { success, getPrint, info, warn, whisper } = require("../utils/log_tool");
7
+ const { BaseCommand } = require("./base");
8
+ const path = require("node:path");
9
+ const { progress } = require("../utils/display_tool");
10
+ const { createWriteStream, readFileSync } = require("node:fs");
11
+ const { getCache, setCache } = require("../utils/cache_tool");
12
+ const crypto = require("node:crypto");
13
+ const { queueAsync } = require("../utils/func_tool");
30
14
 
31
15
  class AliOssCommand extends BaseCommand {
32
16
  async execute() {
33
-
34
- let config = this.selfData.config;
35
- let mode = this.selfData.mode;
17
+ const config = this.selfData.config;
18
+ const mode = this.selfData.mode;
36
19
 
37
20
  return await new Promise((resolve, reject) => {
38
- const OSS = require('ali-oss');
21
+ const OSS = require("ali-oss");
39
22
  // 初始化OSS客户端。请将以下参数替换为您自己的配置信息。
40
23
  const client = new OSS({
41
24
  region: config.region, // 示例:'oss-cn-hangzhou',填写Bucket所在地域。
@@ -45,148 +28,228 @@ class AliOssCommand extends BaseCommand {
45
28
  });
46
29
  switch (mode) {
47
30
  case "DOWNLOAD": {
48
- let src = this.selfData.src;
49
- let dst = get_full_path(this.selfData.dst);
50
- let timeout = this.selfData.options && this.selfData.options.timeout || 1000 * 60 * 2;
51
- client.get(src, dst, {
52
- timeout,
53
- }).then((result) => {
54
- resolve(result);
55
- }).catch((err) => {
56
- reject(err);
57
- });
31
+ const src = this.selfData.src;
32
+ const dst = get_full_path(this.selfData.dst);
33
+ const timeout =
34
+ this.selfData.options?.timeout || 1000 * 60 * 2;
35
+ client
36
+ .get(src, dst, {
37
+ timeout,
38
+ })
39
+ .then((result) => {
40
+ resolve(result);
41
+ })
42
+ .catch((err) => {
43
+ reject(err);
44
+ });
58
45
  break;
59
46
  }
60
47
  case "UPLOAD_FILE":
61
48
  case "UPLOAD": {
62
- let dst = this.selfData.dst;
63
- let src = get_full_path(this.selfData.src);
64
- let timeout = this.selfData.options && this.selfData.options.timeout || 1000 * 60 * 2;
49
+ const dst = this.selfData.dst;
50
+ const src = get_full_path(this.selfData.src);
51
+ const timeout =
52
+ this.selfData.options?.timeout || 1000 * 60 * 2;
65
53
  info("");
66
54
  info(`开始上传 ${path.basename(src)} 到 ${dst}`);
67
- client.put(dst, src, {
68
- timeout,
69
- }).then((result) => {
70
- resolve(result);
71
- })
72
- .catch((err) => {
73
- reject(err);
74
- });
55
+ client
56
+ .put(dst, src, {
57
+ timeout,
58
+ })
59
+ .then((result) => {
60
+ resolve(result);
61
+ })
62
+ .catch((err) => {
63
+ reject(err);
64
+ });
75
65
  break;
76
66
  }
77
67
  case "UPLOAD_FILES": {
78
- let dst_folder = this.selfData.dst;
79
- let concurrency = this.selfData.options && this.selfData.options.concurrency || 5;
80
- let timeout = this.selfData.options && this.selfData.options.timeout || 1000 * 60 * 5;
81
- let strategy = this.selfData.options && this.selfData.options.strategy || "hash";
82
- let base = this.selfData.base;
83
- whisper(`在 ${base} 中收集要上传的文件...`, undefined, true);
84
- let srcs = get_file_list(this.selfData.src, undefined, true);
68
+ const dst_folder = this.selfData.dst;
69
+ const concurrency = this.selfData.options?.concurrency || 5;
70
+ const timeout =
71
+ this.selfData.options?.timeout || 1000 * 60 * 5;
72
+ const strategy = this.selfData.options?.strategy || "hash";
73
+ const base = this.selfData.base;
74
+ whisper(
75
+ `在 ${base} 中收集要上传的文件...`,
76
+ undefined,
77
+ true,
78
+ );
79
+ const srcs = get_file_list(
80
+ this.selfData.src,
81
+ undefined,
82
+ true,
83
+ );
85
84
  let retryTimes = 0;
86
- let maxRetryTimes = 3;
87
- let cacheKey = `ali_oss/${config.bucket}/${dst_folder}`.replace(/\//g, ".");
88
- let cacheType = this.selfData.cache_type;
89
- let cacheParam = this.selfData.cache_param;
85
+ const maxRetryTimes = 3;
86
+ const cacheKey =
87
+ `ali_oss/${config.bucket}/${dst_folder}`.replace(
88
+ /\//g,
89
+ ".",
90
+ );
91
+ const cacheType = this.selfData.cache_type;
92
+ const cacheParam = this.selfData.cache_param;
90
93
  let cachedFiles = null;
91
- getCache(cacheKey, cacheType, cacheParam).then((_cachedFiles) => {
92
- cachedFiles = _cachedFiles;
93
- info(`cacheKey=${cacheKey}, cacheType=${cacheType}, cacheParam=${cacheParam},cachedFiles=${JSON.stringify(cachedFiles).substring(0, 20)}`);
94
- if (!cachedFiles || !Object.keys(cachedFiles).length) {
95
- let marker = null;
96
- var objs = [];
97
- async function list () {
98
- do {
99
- const result = await client.list({
100
- prefix: dst_folder + "/",
101
- marker: marker,
94
+ getCache(cacheKey, cacheType, cacheParam).then(
95
+ (_cachedFiles) => {
96
+ cachedFiles = _cachedFiles;
97
+ info(
98
+ `cacheKey=${cacheKey}, cacheType=${cacheType}, cacheParam=${cacheParam},cachedFiles=${JSON.stringify(cachedFiles).substring(0, 20)}`,
99
+ );
100
+ if (
101
+ !cachedFiles ||
102
+ !Object.keys(cachedFiles).length
103
+ ) {
104
+ let marker = null;
105
+ var objs = [];
106
+ async function list() {
107
+ do {
108
+ const result = await client.list({
109
+ prefix: `${dst_folder}/`,
110
+ marker: marker,
111
+ });
112
+ marker = result.nextMarker;
113
+ objs.push.apply(objs, result.objects);
114
+ } while (marker);
115
+ return objs;
116
+ }
117
+ list().then((objs) => {
118
+ cachedFiles = {};
119
+ objs.forEach((obj) => {
120
+ cachedFiles[obj.name] = obj.etag
121
+ .replaceAll('"', "")
122
+ .toLowerCase();
102
123
  });
103
- marker = result.nextMarker;
104
- objs.push.apply(objs, result.objects);
105
- } while (marker);
106
- return objs;
107
- }
108
- list().then(objs => {
109
- cachedFiles = {};
110
- objs.forEach(obj => {
111
- cachedFiles[obj.name] = obj.etag.replaceAll("\"", "").toLowerCase();
124
+ setCache(
125
+ cacheKey,
126
+ cachedFiles,
127
+ cacheType,
128
+ cacheParam,
129
+ );
130
+ uploadFiles(srcs);
112
131
  });
113
- setCache(cacheKey, cachedFiles, cacheType, cacheParam);
132
+ } else {
114
133
  uploadFiles(srcs);
115
- });
116
- } else {
117
- uploadFiles(srcs);
118
- }
119
- function uploadFiles(srcs) {
120
- let rawLength = srcs.length;
121
- // 过滤文件
122
- srcs = srcs.filter(src => {
123
- let cachedValue = cachedFiles[path.join(dst_folder, path.relative(base, src)).replace(/\\/g, "/")];
124
- switch(strategy) {
125
- case "lazy": {
126
- if (cachedValue) {
127
- return false;
134
+ }
135
+ function uploadFiles(srcs) {
136
+ const rawLength = srcs.length;
137
+ // 过滤文件
138
+ srcs = srcs.filter((src) => {
139
+ const cachedValue =
140
+ cachedFiles[
141
+ path
142
+ .join(
143
+ dst_folder,
144
+ path.relative(base, src),
145
+ )
146
+ .replace(/\\/g, "/")
147
+ ];
148
+ switch (strategy) {
149
+ case "lazy": {
150
+ if (cachedValue) {
151
+ return false;
152
+ }
153
+ break;
128
154
  }
129
- break;
130
- }
131
- case "hash": {
132
- let hash = crypto.createHash("md5").update(readFileSync(src)).digest("hex");
133
- if (cachedValue == hash) {
134
- return false;
155
+ case "hash": {
156
+ const hash = crypto
157
+ .createHash("md5")
158
+ .update(readFileSync(src))
159
+ .digest("hex");
160
+ if (cachedValue === hash) {
161
+ return false;
162
+ }
163
+ break;
164
+ }
165
+ case "force": {
166
+ break;
167
+ }
168
+ default: {
169
+ throw `Unkown Strategy ${strategy}`;
170
+ break;
135
171
  }
136
- break;
137
- }
138
- case "force": {
139
-
140
- break;
141
- }
142
- default: {
143
- throw `Unkown Strategy ${strategy}`;
144
- break;
145
172
  }
146
- }
147
- return true;
148
- });
149
- info(`预处理完成!`, "\r");
150
- info(`实际 ${srcs.length}, 忽略 ${rawLength - srcs.length}, 共计 ${rawLength}`);
151
-
152
- let tasks = srcs.map((src) => {
153
- let dst = path.join(dst_folder, path.relative(base, src)).replace(/\\/g, "/")
154
- return client.put.bind(client, dst, src, {
155
- timeout,
173
+ return true;
156
174
  });
157
- });
158
- queueAsync(tasks, concurrency, (done, total, index, ret) => {
159
- progress(done, total, {
160
- desc: path.relative(base, srcs[index]) + " " + (ret ? (ret.err ? "上传失败!" : "上传成功!") : "上传中..."),
161
- depth: 0,
175
+ info(`预处理完成!`, "\r");
176
+ info(
177
+ `实际 ${srcs.length}, 忽略 ${rawLength - srcs.length}, 共计 ${rawLength}`,
178
+ );
179
+
180
+ const tasks = srcs.map((src) => {
181
+ const dst = path
182
+ .join(
183
+ dst_folder,
184
+ path.relative(base, src),
185
+ )
186
+ .replace(/\\/g, "/");
187
+ return client.put.bind(client, dst, src, {
188
+ timeout,
189
+ });
162
190
  });
163
- }).then((result) => {
164
- var retrySrcs = [];
165
- for(var i = 0; i < result.length; i++) {
166
- if (result[i].err) {
167
- retrySrcs.push(srcs[i]);
168
- warn(`上传文件 ${path.relative(base, srcs[i])} 失败: ${result[i].err}`);
169
- } else {
170
- // 当前上传的,存储为 hash
171
- let dst = path.join(dst_folder, path.relative(base, srcs[i])).replace(/\\/g, "/")
172
- cachedFiles[dst] = crypto.createHash("md5").update(readFileSync(srcs[i])).digest("hex");
191
+ queueAsync(
192
+ tasks,
193
+ concurrency,
194
+ (done, total, index, ret) => {
195
+ progress(done, total, {
196
+ desc: `${path.relative(base, srcs[index])} ${ret ? (ret.err ? "上传失败!" : "上传成功!") : "上传中..."}`,
197
+ depth: 0,
198
+ });
199
+ },
200
+ ).then((result) => {
201
+ var retrySrcs = [];
202
+ for (var i = 0; i < result.length; i++) {
203
+ if (result[i].err) {
204
+ retrySrcs.push(srcs[i]);
205
+ warn(
206
+ `上传文件 ${path.relative(base, srcs[i])} 失败: ${result[i].err}`,
207
+ );
208
+ } else {
209
+ // 当前上传的,存储为 hash
210
+ const dst = path
211
+ .join(
212
+ dst_folder,
213
+ path.relative(
214
+ base,
215
+ srcs[i],
216
+ ),
217
+ )
218
+ .replace(/\\/g, "/");
219
+ cachedFiles[dst] = crypto
220
+ .createHash("md5")
221
+ .update(readFileSync(srcs[i]))
222
+ .digest("hex");
223
+ }
173
224
  }
174
- }
175
- if (retrySrcs.length > 0) {
176
- retryTimes++;
177
- if (retryTimes > maxRetryTimes) {
178
- setCache(cacheKey, cachedFiles, cacheType, cacheParam);
179
- reject(`上传文件失败,重试次数超过 ${maxRetryTimes} 次。`);
180
- return;
225
+ if (retrySrcs.length > 0) {
226
+ retryTimes++;
227
+ if (retryTimes > maxRetryTimes) {
228
+ setCache(
229
+ cacheKey,
230
+ cachedFiles,
231
+ cacheType,
232
+ cacheParam,
233
+ );
234
+ reject(
235
+ `上传文件失败,重试次数超过 ${maxRetryTimes} 次。`,
236
+ );
237
+ return;
238
+ }
239
+ uploadFiles(retrySrcs);
240
+ } else {
241
+ setCache(
242
+ cacheKey,
243
+ cachedFiles,
244
+ cacheType,
245
+ cacheParam,
246
+ );
247
+ resolve(true);
181
248
  }
182
- uploadFiles(retrySrcs);
183
- } else {
184
- setCache(cacheKey, cachedFiles, cacheType, cacheParam);
185
- resolve(true);
186
- }
187
- });
188
- }
189
- })
249
+ });
250
+ }
251
+ },
252
+ );
190
253
  break;
191
254
  }
192
255
  default: {
@@ -200,4 +263,4 @@ class AliOssCommand extends BaseCommand {
200
263
 
201
264
  module.exports = {
202
265
  AliOssCommand,
203
- };
266
+ };
@@ -1,56 +1,54 @@
1
- const {
2
- BaseCommand
3
- } = require("./base");
4
-
5
- /**
6
- * 把数组(content)中的元素使用指定符号(delimiter)分割,组合得到指定属性名(props)的对象数组(ret)
7
- * @example
8
- * content = ["Key1,Key2,Key3", "Value1,Value2,Value3"];
9
- * delimiter = ",";
10
- * props = "k,v"
11
- * // 得到结果
12
- * ret = [
13
- * {k: "Key1", v: "Value1"},
14
- * {k: "Key2", v: "Value2"},
15
- * {k: "Key3", v: "Value3"},
16
- * ]
17
- */
18
- class AssembleCommand extends BaseCommand {
19
- async execute() {
20
- let delimiter = this.selfData.delimiter;
21
- if (delimiter) {
22
- delimiter = new RegExp(delimiter);
23
- }
24
- let props = this.selfData.props;
25
- if (delimiter && typeof props === "string") {
26
- props = props.split(delimiter);
27
- }
28
- let arrays = this.content.map(v => delimiter && typeof v === "string" ? v.split(delimiter) : v);
29
- let num_item = arrays.reduce((prev, curr) => {
30
- return Math.max(prev, curr.length);
31
- }, 0);
32
- let ret = [];
33
- for (let idx_item = 0; idx_item < num_item; ++idx_item) {
34
- let tmp = {};
35
- props.forEach((v, prop_idx) => {
36
- tmp[v] = arrays[prop_idx][idx_item];
37
- });
38
- ret.push(tmp);
39
- }
40
- return ret;
41
- }
42
-
43
- getRequiredParams() {
44
- return [
45
- 'props'
46
- ];
47
- }
48
-
49
- getRequireContent() {
50
- return true;
51
- }
52
- }
53
-
54
- module.exports = {
55
- AssembleCommand,
56
- };
1
+ const { BaseCommand } = require("./base");
2
+
3
+ /**
4
+ * 把数组(content)中的元素使用指定符号(delimiter)分割,组合得到指定属性名(props)的对象数组(ret)
5
+ * @example
6
+ * content = ["Key1,Key2,Key3", "Value1,Value2,Value3"];
7
+ * delimiter = ",";
8
+ * props = "k,v"
9
+ * // 得到结果
10
+ * ret = [
11
+ * {k: "Key1", v: "Value1"},
12
+ * {k: "Key2", v: "Value2"},
13
+ * {k: "Key3", v: "Value3"},
14
+ * ]
15
+ */
16
+ class AssembleCommand extends BaseCommand {
17
+ async execute() {
18
+ let delimiter = this.selfData.delimiter;
19
+ if (delimiter) {
20
+ delimiter = new RegExp(delimiter);
21
+ }
22
+ let props = this.selfData.props;
23
+ if (delimiter && typeof props === "string") {
24
+ props = props.split(delimiter);
25
+ }
26
+ const arrays = this.content.map((v) =>
27
+ delimiter && typeof v === "string" ? v.split(delimiter) : v,
28
+ );
29
+ const num_item = arrays.reduce((prev, curr) => {
30
+ return Math.max(prev, curr.length);
31
+ }, 0);
32
+ const ret = [];
33
+ for (let idx_item = 0; idx_item < num_item; ++idx_item) {
34
+ const tmp = {};
35
+ props.forEach((v, prop_idx) => {
36
+ tmp[v] = arrays[prop_idx][idx_item];
37
+ });
38
+ ret.push(tmp);
39
+ }
40
+ return ret;
41
+ }
42
+
43
+ getRequiredParams() {
44
+ return ["props"];
45
+ }
46
+
47
+ getRequireContent() {
48
+ return true;
49
+ }
50
+ }
51
+
52
+ module.exports = {
53
+ AssembleCommand,
54
+ };