@maiyunnet/kebab 2.0.15 → 3.0.0

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 (81) hide show
  1. package/README.md +1 -5
  2. package/index.d.ts +1 -1
  3. package/index.js +16 -18
  4. package/lib/buffer.js +7 -20
  5. package/lib/captcha.js +6 -44
  6. package/lib/consistent.js +8 -51
  7. package/lib/core.d.ts +4 -4
  8. package/lib/core.js +70 -132
  9. package/lib/crypto.js +43 -99
  10. package/lib/db.d.ts +5 -5
  11. package/lib/db.js +31 -68
  12. package/lib/dns.d.ts +1 -1
  13. package/lib/dns.js +12 -50
  14. package/lib/fs.js +26 -81
  15. package/lib/jwt.d.ts +3 -3
  16. package/lib/jwt.js +9 -50
  17. package/lib/kv.d.ts +4 -4
  18. package/lib/kv.js +31 -69
  19. package/lib/lan.js +4 -41
  20. package/lib/net/cacert.pem +78 -2
  21. package/lib/net/formdata.js +5 -42
  22. package/lib/net/request.d.ts +2 -2
  23. package/lib/net/request.js +3 -42
  24. package/lib/net/response.d.ts +1 -1
  25. package/lib/net/response.js +1 -5
  26. package/lib/net.d.ts +5 -5
  27. package/lib/net.js +24 -73
  28. package/lib/s3.d.ts +1 -1
  29. package/lib/s3.js +23 -62
  30. package/lib/scan.d.ts +3 -3
  31. package/lib/scan.js +10 -50
  32. package/lib/session.d.ts +3 -3
  33. package/lib/session.js +9 -46
  34. package/lib/sql.d.ts +2 -2
  35. package/lib/sql.js +9 -50
  36. package/lib/ssh/sftp.js +5 -46
  37. package/lib/ssh/shell.js +2 -39
  38. package/lib/ssh.d.ts +2 -2
  39. package/lib/ssh.js +5 -43
  40. package/lib/text.d.ts +1 -1
  41. package/lib/text.js +40 -104
  42. package/lib/time.d.ts +1 -1
  43. package/lib/time.js +10 -50
  44. package/lib/turnstile.d.ts +1 -1
  45. package/lib/turnstile.js +6 -43
  46. package/lib/ws.d.ts +10 -2
  47. package/lib/ws.js +70 -53
  48. package/lib/zip.d.ts +1 -1
  49. package/lib/zip.js +10 -57
  50. package/lib/zlib.js +24 -89
  51. package/main.js +6 -44
  52. package/package.json +9 -8
  53. package/sys/child.js +10 -45
  54. package/sys/cmd.js +8 -43
  55. package/sys/ctr.d.ts +5 -5
  56. package/sys/ctr.js +11 -49
  57. package/sys/master.js +11 -46
  58. package/sys/mod.d.ts +9 -5
  59. package/sys/mod.js +28 -214
  60. package/sys/route.d.ts +2 -2
  61. package/sys/route.js +26 -64
  62. package/types/index.d.ts +1 -0
  63. package/www/example/ctr/main.d.ts +1 -1
  64. package/www/example/ctr/main.js +2 -38
  65. package/www/example/ctr/middle.d.ts +2 -2
  66. package/www/example/ctr/middle.js +2 -38
  67. package/www/example/ctr/test.d.ts +2 -2
  68. package/www/example/ctr/test.js +65 -72
  69. package/www/example/mod/test.d.ts +2 -2
  70. package/www/example/mod/test.js +4 -42
  71. package/www/example/mod/testdata.d.ts +1 -1
  72. package/www/example/mod/testdata.js +3 -8
  73. package/www/example/ws/mproxy.d.ts +1 -1
  74. package/www/example/ws/mproxy.js +6 -41
  75. package/www/example/ws/rproxy.d.ts +1 -1
  76. package/www/example/ws/rproxy.js +5 -40
  77. package/www/example/ws/rsocket.d.ts +4 -0
  78. package/www/example/ws/rsocket.js +12 -0
  79. package/www/example/ws/test.d.ts +6 -1
  80. package/www/example/ws/test.js +13 -42
  81. package/eslint.config.js +0 -22
package/lib/core.js CHANGED
@@ -1,82 +1,20 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.global = exports.REAL_IP_CF = exports.REAL_IP_X = exports.CONVERT62_CHAR = exports.RANDOM_LUNS = exports.RANDOM_V = exports.RANDOM_LUN = exports.RANDOM_LU = exports.RANDOM_LN = exports.RANDOM_UN = exports.RANDOM_L = exports.RANDOM_U = exports.RANDOM_N = exports.globalConfig = void 0;
37
- exports.setCookie = setCookie;
38
- exports.rand = rand;
39
- exports.random = random;
40
- exports.convert62 = convert62;
41
- exports.unconvert62 = unconvert62;
42
- exports.purify = purify;
43
- exports.checkType = checkType;
44
- exports.muid = muid;
45
- exports.ip = ip;
46
- exports.realIP = realIP;
47
- exports.sleep = sleep;
48
- exports.objectSort = objectSort;
49
- exports.emptyObject = emptyObject;
50
- exports.passThroughAppend = passThroughAppend;
51
- exports.exec = exec;
52
- exports.sendReload = sendReload;
53
- exports.sendRestart = sendRestart;
54
- exports.setGlobal = setGlobal;
55
- exports.removeGlobal = removeGlobal;
56
- exports.updateCode = updateCode;
57
- exports.log = log;
58
- exports.getLog = getLog;
59
- exports.ls = ls;
60
- exports.clone = clone;
61
- exports.debug = debug;
62
- exports.display = display;
63
1
  /**
64
2
  * Project: Kebab, User: JianSuoQiYue
65
3
  * Date: 2019-5-3 23:54
66
4
  * Last: 2020-4-11 22:34:58, 2022-10-2 14:13:06, 2022-12-28 20:33:24, 2023-12-15 11:49:02, 2024-7-2 15:23:35, 2025-6-13 19:45:53
67
5
  */
68
- const cp = __importStar(require("child_process"));
69
- const stream = __importStar(require("stream"));
70
- const lTime = __importStar(require("~/lib/time"));
71
- const lFs = __importStar(require("~/lib/fs"));
72
- const lText = __importStar(require("~/lib/text"));
73
- const lNet = __importStar(require("~/lib/net"));
74
- const lCrypto = __importStar(require("~/lib/crypto"));
75
- const lResponse = __importStar(require("~/lib/net/response"));
76
- const sCtr = __importStar(require("~/sys/ctr"));
77
- const kebab = __importStar(require("~/index"));
6
+ import * as cp from 'child_process';
7
+ import * as stream from 'stream';
8
+ import * as lTime from '../lib/time.js';
9
+ import * as lFs from '../lib/fs.js';
10
+ import * as lText from '../lib/text.js';
11
+ import * as lNet from '../lib/net.js';
12
+ import * as lCrypto from '../lib/crypto.js';
13
+ import * as lResponse from '../lib/net/response.js';
14
+ import * as sCtr from '../sys/ctr.js';
15
+ import * as kebab from '../index.js';
78
16
  /** --- 全局参数 --- */
79
- exports.globalConfig = {};
17
+ export const globalConfig = {};
80
18
  /**
81
19
  * --- 设置 cookie ---
82
20
  * @param ctr ctr 实例
@@ -84,7 +22,7 @@ exports.globalConfig = {};
84
22
  * @param value 值
85
23
  * @param opt 选项,ttl, 默认和 undefined 为关闭浏览器失效
86
24
  */
87
- function setCookie(ctr, name, value, opt = {}) {
25
+ export function setCookie(ctr, name, value, opt = {}) {
88
26
  const res = ctr.getPrototype('_res');
89
27
  if (!res) {
90
28
  return;
@@ -111,7 +49,7 @@ function setCookie(ctr, name, value, opt = {}) {
111
49
  * @param max <= 最大值
112
50
  * @param prec 保留几位小数
113
51
  */
114
- function rand(min, max, prec = 0) {
52
+ export function rand(min, max, prec = 0) {
115
53
  if (prec < 0) {
116
54
  prec = 0;
117
55
  }
@@ -121,22 +59,22 @@ function rand(min, max, prec = 0) {
121
59
  return Math.round(Math.random() * (max - min) + min) / p;
122
60
  }
123
61
  // --- 随机 ---
124
- exports.RANDOM_N = '0123456789';
125
- exports.RANDOM_U = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
126
- exports.RANDOM_L = 'abcdefghijklmnopqrstuvwxyz';
127
- exports.RANDOM_UN = exports.RANDOM_U + exports.RANDOM_N;
128
- exports.RANDOM_LN = exports.RANDOM_L + exports.RANDOM_N;
129
- exports.RANDOM_LU = exports.RANDOM_L + exports.RANDOM_U;
130
- exports.RANDOM_LUN = exports.RANDOM_L + exports.RANDOM_U + exports.RANDOM_N;
131
- exports.RANDOM_V = 'ACEFGHJKLMNPRSTWXY34567';
132
- exports.RANDOM_LUNS = exports.RANDOM_LUN + '()`~!@#$%^&*-+=_|{}[]:;"<>,.?/]"';
62
+ export const RANDOM_N = '0123456789';
63
+ export const RANDOM_U = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
64
+ export const RANDOM_L = 'abcdefghijklmnopqrstuvwxyz';
65
+ export const RANDOM_UN = RANDOM_U + RANDOM_N;
66
+ export const RANDOM_LN = RANDOM_L + RANDOM_N;
67
+ export const RANDOM_LU = RANDOM_L + RANDOM_U;
68
+ export const RANDOM_LUN = RANDOM_L + RANDOM_U + RANDOM_N;
69
+ export const RANDOM_V = 'ACEFGHJKLMNPRSTWXY34567';
70
+ export const RANDOM_LUNS = RANDOM_LUN + '()`~!@#$%^&*-+=_|{}[]:;"<>,.?/]"';
133
71
  /**
134
72
  * --- 生成随机字符串 ---
135
73
  * @param length 长度
136
74
  * @param source 采样值
137
75
  * @param block 排除的字符
138
76
  */
139
- function random(length = 8, source = exports.RANDOM_LN, block = '') {
77
+ export function random(length = 8, source = RANDOM_LN, block = '') {
140
78
  // --- 剔除 block 字符 ---
141
79
  let len = block.length;
142
80
  if (len > 0) {
@@ -154,18 +92,18 @@ function random(length = 8, source = exports.RANDOM_LN, block = '') {
154
92
  }
155
93
  return temp;
156
94
  }
157
- exports.CONVERT62_CHAR = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
95
+ export const CONVERT62_CHAR = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
158
96
  /**
159
97
  * --- 将 10 进制转换为 62 进制 ---
160
98
  * @param n 10 进制数字最大 9223372036854775807n
161
99
  */
162
- function convert62(n) {
100
+ export function convert62(n) {
163
101
  if (typeof n !== 'bigint') {
164
102
  n = BigInt(n);
165
103
  }
166
104
  let res = '';
167
105
  while (n > 0) {
168
- res = exports.CONVERT62_CHAR[Number(n % 62n)] + res;
106
+ res = CONVERT62_CHAR[Number(n % 62n)] + res;
169
107
  n = n / 62n;
170
108
  }
171
109
  return res;
@@ -174,11 +112,11 @@ function convert62(n) {
174
112
  * --- 将 62 进制转换为 10 进制 ---
175
113
  * @param n 62 进制数字最大 aZl8N0y58M7
176
114
  */
177
- function unconvert62(n) {
115
+ export function unconvert62(n) {
178
116
  let res = 0n;
179
117
  const nl = n.length;
180
118
  for (let i = 1; i <= nl; ++i) {
181
- res += BigInt(exports.CONVERT62_CHAR.indexOf(n[i - 1])) * (62n ** BigInt(nl - i));
119
+ res += BigInt(CONVERT62_CHAR.indexOf(n[i - 1])) * (62n ** BigInt(nl - i));
182
120
  }
183
121
  return res;
184
122
  }
@@ -186,7 +124,7 @@ function unconvert62(n) {
186
124
  * --- 去除 html 的空白符、换行以及注释 ---
187
125
  * @param text 要纯净的字符串
188
126
  */
189
- function purify(text) {
127
+ export function purify(text) {
190
128
  text = '>' + text + '<';
191
129
  const keepScripts = [];
192
130
  const keepPres = [];
@@ -215,7 +153,7 @@ function purify(text) {
215
153
  * @param type 示例组
216
154
  * @param tree 当前树,无需传入
217
155
  */
218
- function checkType(val, type, tree = 'root') {
156
+ export function checkType(val, type, tree = 'root') {
219
157
  /** --- 要校验的对象 --- */
220
158
  const vtype = typeof val;
221
159
  if (Array.isArray(type)) {
@@ -286,7 +224,7 @@ function checkType(val, type, tree = 'root') {
286
224
  * @param ctr Ctr 对象
287
225
  * @param opt len: 8 - 32, 默认 8; bin: 是否含有大小写, 默认 true; key: 多样性混合, 默认空; insert: 插入指定字符, 最好不超过 2 字符,默认空,num: 是否含有数字,默认 true
288
226
  */
289
- function muid(ctr, opt = {}) {
227
+ export function muid(ctr, opt = {}) {
290
228
  const len = opt.len ?? 8;
291
229
  const bin = opt.bin ?? true;
292
230
  const key = opt.key ?? '';
@@ -305,14 +243,14 @@ function muid(ctr, opt = {}) {
305
243
  return '';
306
244
  }
307
245
  // --- 生成随机数 ---
308
- const over = random(len - 1 - ilen, bin ? (num ? exports.RANDOM_LUN : exports.RANDOM_LU) : (num ? exports.RANDOM_LN : exports.RANDOM_L)) + char[20];
246
+ const over = random(len - 1 - ilen, bin ? (num ? RANDOM_LUN : RANDOM_LU) : (num ? RANDOM_LN : RANDOM_L)) + char[20];
309
247
  return over[0] + insert + over.slice(1);
310
248
  }
311
249
  /**
312
250
  * --- 获取 IP(非安全 IP)---
313
251
  * @param ctr
314
252
  */
315
- function ip(ctr, req) {
253
+ export function ip(ctr, req) {
316
254
  const headers = ctr instanceof sCtr.Ctr ? ctr.getPrototype('_headers') : ctr;
317
255
  if (typeof headers['cf-connecting-ip'] === 'string') {
318
256
  return headers['cf-connecting-ip'];
@@ -332,14 +270,14 @@ function ip(ctr, req) {
332
270
  return req.socket.remoteAddress ?? '';
333
271
  }
334
272
  }
335
- exports.REAL_IP_X = 'x-forwarded-for';
336
- exports.REAL_IP_CF = 'cf-connecting-ip';
273
+ export const REAL_IP_X = 'x-forwarded-for';
274
+ export const REAL_IP_CF = 'cf-connecting-ip';
337
275
  /**
338
276
  * --- 获取直连 IP(安全 IP) ---
339
277
  * @param ctr
340
278
  * @param name 输入安全的 header
341
279
  */
342
- function realIP(ctr, name = '') {
280
+ export function realIP(ctr, name = '') {
343
281
  const headers = ctr.getPrototype('_headers');
344
282
  if (name !== '') {
345
283
  const value = headers[name];
@@ -355,7 +293,7 @@ function realIP(ctr, name = '') {
355
293
  * --- 间隔一段时间 ---
356
294
  * @param ms 间隔毫秒
357
295
  */
358
- function sleep(ms) {
296
+ export function sleep(ms) {
359
297
  return new Promise(function (resolve) {
360
298
  setTimeout(function () {
361
299
  resolve();
@@ -366,7 +304,7 @@ function sleep(ms) {
366
304
  * --- 将对象进行升序排列 ---
367
305
  * @param o 要重排的对象
368
306
  */
369
- function objectSort(o) {
307
+ export function objectSort(o) {
370
308
  const ordered = {};
371
309
  const list = Object.keys(o).sort();
372
310
  for (const key of list) {
@@ -384,7 +322,7 @@ function objectSort(o) {
384
322
  * @param obj 要清除的对象
385
323
  * @patam deep 也将子项都清空,如果子项有独立引用的话也要清空的话则要设置为 true
386
324
  */
387
- function emptyObject(obj, deep = false) {
325
+ export function emptyObject(obj, deep = false) {
388
326
  const keys = Object.keys(obj);
389
327
  for (const key of keys) {
390
328
  if (deep) {
@@ -402,7 +340,7 @@ function emptyObject(obj, deep = false) {
402
340
  * @param data 数组
403
341
  * @param end 是否关闭写入,默认是,关闭后 passThrough 不能被写入,但仍然可读
404
342
  */
405
- async function passThroughAppend(passThrough, data, end = true) {
343
+ export async function passThroughAppend(passThrough, data, end = true) {
406
344
  for (const item of data) {
407
345
  if (item instanceof stream.Readable || item instanceof lResponse.Response) {
408
346
  const stm = item instanceof stream.Readable ? item : item.getStream();
@@ -433,7 +371,7 @@ async function passThroughAppend(passThrough, data, end = true) {
433
371
  * --- 执行命令行 ---
434
372
  * @param command 命令字符串
435
373
  */
436
- function exec(command) {
374
+ export function exec(command) {
437
375
  return new Promise(function (resolve) {
438
376
  cp.exec(command, function (err, stdout) {
439
377
  if (err) {
@@ -448,7 +386,7 @@ function exec(command) {
448
386
  * --- 向主进程(或局域网同代码机子)发送广播将进行 reload 操作,等待回传 ---
449
387
  * --- 主要作用除代码热更新以外的其他情况 ---
450
388
  */
451
- async function sendReload(hosts) {
389
+ export async function sendReload(hosts) {
452
390
  if (!hosts) {
453
391
  // --- 本地模式 ---
454
392
  // eslint-disable-next-line no-console
@@ -459,17 +397,17 @@ async function sendReload(hosts) {
459
397
  return [];
460
398
  }
461
399
  if (hosts === 'config') {
462
- hosts = exports.globalConfig.hosts;
400
+ hosts = globalConfig.hosts;
463
401
  }
464
402
  // --- 局域网模式 ---
465
403
  const time = lTime.stamp();
466
404
  /** --- 返回成功的 host --- */
467
405
  const rtn = [];
468
406
  for (const host of hosts) {
469
- const res = await lNet.get('http://' + host + ':' + exports.globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
407
+ const res = await lNet.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
470
408
  'action': 'reload',
471
409
  'time': time
472
- }), exports.globalConfig.rpcSecret), {
410
+ }), globalConfig.rpcSecret), {
473
411
  'timeout': 2
474
412
  });
475
413
  const content = await res.getContent();
@@ -487,7 +425,7 @@ async function sendReload(hosts) {
487
425
  * --- 向主进程(或局域网同代码机子)发送广播将进行 restart 操作,停止监听并启动新进程,老进程在连接全部断开后自行销毁 ---
488
426
  * --- 主要用作不间断的代码热更新 ---
489
427
  */
490
- async function sendRestart(hosts) {
428
+ export async function sendRestart(hosts) {
491
429
  if (!hosts) {
492
430
  // --- 本地模式 ---
493
431
  // eslint-disable-next-line no-console
@@ -498,17 +436,17 @@ async function sendRestart(hosts) {
498
436
  return [];
499
437
  }
500
438
  if (hosts === 'config') {
501
- hosts = exports.globalConfig.hosts;
439
+ hosts = globalConfig.hosts;
502
440
  }
503
441
  // --- 局域网模式 ---
504
442
  const time = lTime.stamp();
505
443
  /** --- 返回成功的 host --- */
506
444
  const rtn = [];
507
445
  for (const host of hosts) {
508
- const res = await lNet.get('http://' + host + ':' + exports.globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
446
+ const res = await lNet.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
509
447
  'action': 'restart',
510
448
  'time': time
511
- }), exports.globalConfig.rpcSecret), {
449
+ }), globalConfig.rpcSecret), {
512
450
  'timeout': 2
513
451
  });
514
452
  const content = await res.getContent();
@@ -523,14 +461,14 @@ async function sendRestart(hosts) {
523
461
  return rtn;
524
462
  }
525
463
  /** --- 跨进程全局变量 --- */
526
- exports.global = {};
464
+ export const global = {};
527
465
  /**
528
466
  * --- 设置跨线程/跨内网服务器的全局变量 ---
529
467
  * @param key 变量名
530
468
  * @param data 变量值
531
469
  * @param hosts 局域网列表
532
470
  */
533
- async function setGlobal(key, data, hosts) {
471
+ export async function setGlobal(key, data, hosts) {
534
472
  if (!hosts) {
535
473
  // --- 本地模式 ---
536
474
  process.send({
@@ -541,17 +479,17 @@ async function setGlobal(key, data, hosts) {
541
479
  return [];
542
480
  }
543
481
  if (hosts === 'config') {
544
- hosts = exports.globalConfig.hosts;
482
+ hosts = globalConfig.hosts;
545
483
  }
546
484
  // --- 局域网模式 ---
547
485
  const time = lTime.stamp();
548
486
  /** --- 返回成功的 host --- */
549
487
  const rtn = [];
550
488
  for (const host of hosts) {
551
- const res = await lNet.get('http://' + host + ':' + exports.globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
489
+ const res = await lNet.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
552
490
  'action': 'global',
553
491
  'time': time
554
- }), exports.globalConfig.rpcSecret), {
492
+ }), globalConfig.rpcSecret), {
555
493
  'timeout': 2
556
494
  });
557
495
  const content = await res.getContent();
@@ -570,7 +508,7 @@ async function setGlobal(key, data, hosts) {
570
508
  * @param key 变量名
571
509
  * @param hosts 局域网列表
572
510
  */
573
- async function removeGlobal(key, hosts) {
511
+ export async function removeGlobal(key, hosts) {
574
512
  return setGlobal(key, null, hosts);
575
513
  }
576
514
  /**
@@ -581,9 +519,9 @@ async function removeGlobal(key, hosts) {
581
519
  * @param config 是否自动更新 config 的 set.staticVer 为最新,默认更新
582
520
  * @param strict 严格模式,只有存在的文件才会被覆盖,不存在则中途直接报错,默认为 true
583
521
  */
584
- async function updateCode(sourcePath, path, hosts, config = true, strict = true) {
522
+ export async function updateCode(sourcePath, path, hosts, config = true, strict = true) {
585
523
  if (hosts === 'config') {
586
- hosts = exports.globalConfig.hosts;
524
+ hosts = globalConfig.hosts;
587
525
  }
588
526
  hosts ??= ['127.0.0.1'];
589
527
  /** --- 返回成功的 host --- */
@@ -596,10 +534,10 @@ async function updateCode(sourcePath, path, hosts, config = true, strict = true)
596
534
  fd.putString('path', path);
597
535
  fd.putString('config', config ? '1' : '0');
598
536
  fd.putString('strict', strict ? '1' : '0');
599
- const res = await lNet.post('http://' + host + ':' + exports.globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
537
+ const res = await lNet.post('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
600
538
  'action': 'code',
601
539
  'time': lTime.stamp()
602
- }), exports.globalConfig.rpcSecret), fd, {
540
+ }), globalConfig.rpcSecret), fd, {
603
541
  'timeout': 4
604
542
  });
605
543
  const content = await res.getContent();
@@ -624,7 +562,7 @@ async function updateCode(sourcePath, path, hosts, config = true, strict = true)
624
562
  * @param fend 文件名追加
625
563
  * @param opt 选项
626
564
  */
627
- function log(opt, msg, fend = '') {
565
+ export function log(opt, msg, fend = '') {
628
566
  (async () => {
629
567
  let req;
630
568
  let headers;
@@ -701,11 +639,11 @@ function log(opt, msg, fend = '') {
701
639
  * --- 获取日志内容为一个数组 ---
702
640
  * @param opt 参数
703
641
  */
704
- async function getLog(opt) {
642
+ export async function getLog(opt) {
705
643
  opt.host ??= '127.0.0.1';
706
644
  // --- 局域网模式 ---
707
645
  const time = lTime.stamp();
708
- const res = await lNet.get('http://' + opt.host + ':' + exports.globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
646
+ const res = await lNet.get('http://' + opt.host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
709
647
  'action': 'log',
710
648
  'time': time,
711
649
  'hostname': opt.hostname,
@@ -715,7 +653,7 @@ async function getLog(opt) {
715
653
  'start': opt.start,
716
654
  'offset': opt.offset,
717
655
  'limit': opt.limit,
718
- }), exports.globalConfig.rpcSecret), {
656
+ }), globalConfig.rpcSecret), {
719
657
  'timeout': 2
720
658
  });
721
659
  const content = await res.getContent();
@@ -733,16 +671,16 @@ async function getLog(opt) {
733
671
  * --- 获取目录内文件/文件夹列表 ---
734
672
  * @param opt 参数
735
673
  */
736
- async function ls(opt) {
674
+ export async function ls(opt) {
737
675
  opt.host ??= '127.0.0.1';
738
676
  // --- 局域网模式 ---
739
677
  const time = lTime.stamp();
740
- const res = await lNet.get('http://' + opt.host + ':' + exports.globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
678
+ const res = await lNet.get('http://' + opt.host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
741
679
  'action': 'ls',
742
680
  'time': time,
743
681
  'path': opt.path,
744
682
  'encoding': opt.encoding,
745
- }), exports.globalConfig.rpcSecret), {
683
+ }), globalConfig.rpcSecret), {
746
684
  'timeout': 2
747
685
  });
748
686
  const content = await res.getContent();
@@ -760,7 +698,7 @@ async function ls(opt) {
760
698
  * --- 完整的克隆一份数组/对象,Kebab: yes, Mutton: no ---
761
699
  * @param obj 要克隆的对象
762
700
  */
763
- function clone(obj) {
701
+ export function clone(obj) {
764
702
  let newObj = {};
765
703
  if (obj instanceof Array) {
766
704
  newObj = [];
@@ -816,8 +754,8 @@ function clone(obj) {
816
754
  * @param message 参数
817
755
  * @param optionalParams 参数
818
756
  */
819
- function debug(message, ...optionalParams) {
820
- if (!exports.globalConfig.debug) {
757
+ export function debug(message, ...optionalParams) {
758
+ if (!globalConfig.debug) {
821
759
  return;
822
760
  }
823
761
  // eslint-disable-next-line no-console
@@ -828,7 +766,7 @@ function debug(message, ...optionalParams) {
828
766
  * @param message 参数
829
767
  * @param optionalParams 参数
830
768
  */
831
- function display(message, ...optionalParams) {
769
+ export function display(message, ...optionalParams) {
832
770
  // eslint-disable-next-line no-console
833
771
  console.log(message, ...optionalParams);
834
772
  }