@maiyunnet/kebab 2.0.14 → 2.0.15

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 (68) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/captcha.js +2 -2
  4. package/lib/consistent.js +1 -1
  5. package/lib/core.d.ts +42 -18
  6. package/lib/core.js +147 -152
  7. package/lib/crypto.js +2 -2
  8. package/lib/db.d.ts +3 -3
  9. package/lib/db.js +32 -73
  10. package/lib/dns.d.ts +1 -1
  11. package/lib/dns.js +5 -5
  12. package/lib/fs.js +17 -9
  13. package/lib/jwt.d.ts +3 -3
  14. package/lib/jwt.js +5 -5
  15. package/lib/kv.d.ts +2 -2
  16. package/lib/kv.js +2 -2
  17. package/lib/lan.js +1 -1
  18. package/lib/net/formdata.js +2 -2
  19. package/lib/net/request.d.ts +1 -1
  20. package/lib/net/request.js +1 -1
  21. package/lib/net/response.d.ts +1 -1
  22. package/lib/net.d.ts +2 -2
  23. package/lib/net.js +4 -4
  24. package/lib/s3.d.ts +1 -1
  25. package/lib/s3.js +2 -2
  26. package/lib/scan.d.ts +3 -3
  27. package/lib/scan.js +6 -6
  28. package/lib/session.d.ts +3 -3
  29. package/lib/session.js +7 -7
  30. package/lib/sql.d.ts +3 -3
  31. package/lib/sql.js +7 -37
  32. package/lib/ssh/sftp.js +2 -2
  33. package/lib/ssh/shell.js +1 -1
  34. package/lib/text.d.ts +6 -1
  35. package/lib/text.js +9 -1
  36. package/lib/time.d.ts +1 -1
  37. package/lib/time.js +1 -1
  38. package/lib/turnstile.d.ts +1 -1
  39. package/lib/turnstile.js +2 -2
  40. package/lib/ws.d.ts +2 -2
  41. package/lib/ws.js +3 -3
  42. package/lib/zip.d.ts +1 -1
  43. package/lib/zip.js +1 -1
  44. package/package.json +5 -4
  45. package/sys/child.js +43 -84
  46. package/sys/cmd.js +7 -6
  47. package/sys/ctr.d.ts +2 -2
  48. package/sys/master.js +131 -9
  49. package/sys/mod.d.ts +4 -4
  50. package/sys/mod.js +5 -5
  51. package/sys/route.d.ts +1 -1
  52. package/sys/route.js +20 -20
  53. package/www/example/ctr/main.d.ts +1 -1
  54. package/www/example/ctr/main.js +1 -1
  55. package/www/example/ctr/middle.d.ts +2 -2
  56. package/www/example/ctr/middle.js +1 -1
  57. package/www/example/ctr/test.d.ts +3 -2
  58. package/www/example/ctr/test.js +83 -30
  59. package/www/example/mod/test.d.ts +2 -2
  60. package/www/example/mod/test.js +2 -2
  61. package/www/example/mod/testdata.d.ts +1 -1
  62. package/www/example/mod/testdata.js +1 -1
  63. package/www/example/ws/mproxy.d.ts +1 -1
  64. package/www/example/ws/mproxy.js +2 -2
  65. package/www/example/ws/rproxy.d.ts +1 -1
  66. package/www/example/ws/rproxy.js +2 -2
  67. package/www/example/ws/test.d.ts +1 -1
  68. package/www/example/ws/test.js +4 -3
package/index.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * ------------------------
9
9
  */
10
10
  /** --- 当前系统版本号 --- */
11
- export declare const VER = "2.0.14";
11
+ export declare const VER = "2.0.15";
12
12
  /** --- 框架根目录,以 / 结尾 --- */
13
13
  export declare const ROOT_PATH: string;
14
14
  export declare const LIB_PATH: string;
package/index.js CHANGED
@@ -11,7 +11,7 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MOD_CWD = exports.FTMP_CWD = exports.IND_CWD = exports.WWW_CWD = exports.LOG_CWD = exports.LIB_CWD = exports.VHOST_CWD = exports.CERT_CWD = exports.CONF_CWD = exports.ROOT_CWD = exports.SYS_PATH = exports.LIB_PATH = exports.ROOT_PATH = exports.VER = void 0;
13
13
  /** --- 当前系统版本号 --- */
14
- exports.VER = '2.0.14';
14
+ exports.VER = '2.0.15';
15
15
  // --- 服务端用的路径 ---
16
16
  /** --- /xxx/xxx --- */
17
17
  const dirname = __dirname.replace(/\\/g, '/');
package/lib/captcha.js CHANGED
@@ -42,8 +42,8 @@ exports.get = get;
42
42
  */
43
43
  const svgCaptcha = __importStar(require("svg-captcha"));
44
44
  const mime = __importStar(require("@litert/mime"));
45
- const core = __importStar(require("../lib/core"));
46
- const kebab = __importStar(require("../index"));
45
+ const core = __importStar(require("~/lib/core"));
46
+ const kebab = __importStar(require("~/index"));
47
47
  svgCaptcha.loadFont(kebab.LIB_PATH + 'captcha/zcool-addict-italic.ttf');
48
48
  class Captcha {
49
49
  constructor(opt) {
package/lib/consistent.js CHANGED
@@ -45,7 +45,7 @@ exports.findInCircle = findInCircle;
45
45
  * Date: 2022-09-12 10:51:16
46
46
  * Last: 2022-09-12 10:51:20, 2023-3-17 10:52:04, 2023-11-15 11:45:28
47
47
  */
48
- const crypto = __importStar(require("../lib/crypto"));
48
+ const crypto = __importStar(require("~/lib/crypto"));
49
49
  class Consistent {
50
50
  constructor(vcount) {
51
51
  /** --- 虚拟节点数量 --- */
package/lib/core.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as http from 'http';
2
2
  import * as http2 from 'http2';
3
3
  import * as stream from 'stream';
4
- import * as lResponse from '../lib/net/response';
5
- import * as sCtr from '../sys/ctr';
6
- import * as types from '../types';
4
+ import * as lResponse from '~/lib/net/response';
5
+ import * as sCtr from '~/sys/ctr';
6
+ import * as types from '~/types';
7
7
  /** --- 全局参数 --- */
8
8
  export declare const globalConfig: types.IConfig & {
9
9
  'httpPort': number;
@@ -12,6 +12,7 @@ export declare const globalConfig: types.IConfig & {
12
12
  'rpcSecret': string;
13
13
  'debug': boolean;
14
14
  'max': number;
15
+ 'hosts': string[];
15
16
  };
16
17
  /** --- Cookie 设置的选项 --- */
17
18
  export interface ICookieOptions {
@@ -133,23 +134,23 @@ export declare function exec(command: string): Promise<string | false>;
133
134
  * --- 向主进程(或局域网同代码机子)发送广播将进行 reload 操作,等待回传 ---
134
135
  * --- 主要作用除代码热更新以外的其他情况 ---
135
136
  */
136
- export declare function sendReload(hosts?: string[]): Promise<string[]>;
137
+ export declare function sendReload(hosts?: string[] | 'config'): Promise<string[]>;
137
138
  /**
138
139
  * --- 向主进程(或局域网同代码机子)发送广播将进行 restart 操作,停止监听并启动新进程,老进程在连接全部断开后自行销毁 ---
139
140
  * --- 主要用作不间断的代码热更新 ---
140
141
  */
141
- export declare function sendRestart(hosts?: string[]): Promise<string[]>;
142
+ export declare function sendRestart(hosts?: string[] | 'config'): Promise<string[]>;
142
143
  /** --- 跨进程全局变量 --- */
143
144
  export declare const global: Record<string, any>;
144
145
  /**
145
- * --- 设置跨线程的全局变量 ---
146
+ * --- 设置跨线程/跨内网服务器的全局变量 ---
146
147
  * @param key 变量名
147
148
  * @param data 变量值
148
149
  * @param hosts 局域网列表
149
150
  */
150
- export declare function setGlobal(key: string, data: types.Json, hosts?: string[]): Promise<string[]>;
151
+ export declare function setGlobal(key: string, data: types.Json, hosts?: string[] | 'config'): Promise<string[]>;
151
152
  /**
152
- * --- 移除某个跨线程全局变量 ---
153
+ * --- 移除某个跨线程/跨内网服务器全局变量 ---
153
154
  * @param key 变量名
154
155
  * @param hosts 局域网列表
155
156
  */
@@ -160,20 +161,23 @@ export declare function removeGlobal(key: string, hosts?: string[]): Promise<str
160
161
  * @param path 要覆盖到的路径,无所谓是否 / 开头 / 结尾,是对方 kebab 的根据路开始算起
161
162
  * @param hosts 局域网多机部署,不设置默认本机部署
162
163
  * @param config 是否自动更新 config 的 set.staticVer 为最新,默认更新
164
+ * @param strict 严格模式,只有存在的文件才会被覆盖,不存在则中途直接报错,默认为 true
163
165
  */
164
- export declare function updateCode(sourcePath: string, path: string, hosts?: string[], config?: boolean): Promise<Record<string, {
166
+ export declare function updateCode(sourcePath: string, path: string, hosts?: string[] | 'config', config?: boolean, strict?: boolean): Promise<Record<string, {
165
167
  'result': boolean;
166
168
  'return': string;
167
169
  }>>;
168
170
  /** --- log 设置的选项 --- */
169
171
  export interface ILogOptions {
170
- 'path': string;
171
- 'urlFull': string;
172
- 'hostname': string;
173
- 'req': http2.Http2ServerRequest | http.IncomingMessage | null;
174
- 'get': Record<string, types.Json>;
175
- 'cookie': Record<string, string>;
176
- 'headers': http.IncomingHttpHeaders;
172
+ 'path'?: string;
173
+ 'urlFull'?: string;
174
+ 'hostname'?: string;
175
+ 'req'?: http2.Http2ServerRequest | http.IncomingMessage | null;
176
+ 'get'?: Record<string, types.Json>;
177
+ 'cookie'?: Record<string, string>;
178
+ 'jwt'?: Record<string, any>;
179
+ 'session'?: Record<string, any>;
180
+ 'headers'?: http.IncomingHttpHeaders;
177
181
  }
178
182
  /**
179
183
  * --- 写入文件日志 ---
@@ -181,25 +185,45 @@ export interface ILogOptions {
181
185
  * @param fend 文件名追加
182
186
  * @param opt 选项
183
187
  */
184
- export declare function log(opt: sCtr.Ctr | ILogOptions, msg: string, fend?: string): Promise<void>;
188
+ export declare function log(opt: sCtr.Ctr | ILogOptions, msg: string, fend?: string): void;
185
189
  /**
186
190
  * --- 获取日志内容为一个数组 ---
187
191
  * @param opt 参数
188
192
  */
189
193
  export declare function getLog(opt: {
190
194
  /** --- 如 127.0.0.1 --- */
191
- 'host': string;
195
+ 'hostname': string;
192
196
  /** --- 如 2024/08/01/22 --- */
193
197
  'path': string;
194
198
  /** --- 如 -error --- */
195
199
  'fend'?: string;
196
200
  /** --- 仅显示被搜索到的行 --- */
197
201
  'search'?: string;
202
+ /** --- 跳过的字节数,默认不跳过 --- */
203
+ 'start'?: number;
198
204
  /** --- 跳过条数 --- */
199
205
  'offset'?: number;
200
206
  /** --- 最大限制,默认 100 --- */
201
207
  'limit'?: number;
208
+ /** --- 获取局域网服务器的日志,为空代表获取本机的 --- */
209
+ 'host'?: string;
202
210
  }): Promise<string[][] | null | false>;
211
+ /**
212
+ * --- 获取目录内文件/文件夹列表 ---
213
+ * @param opt 参数
214
+ */
215
+ export declare function ls(opt: {
216
+ /** --- 如 2024/08/01/22,无所谓开头结尾 --- */
217
+ 'path': string;
218
+ 'encoding'?: BufferEncoding;
219
+ /** --- 获取局域网服务器的目录列表,为空代表获取本机的 --- */
220
+ 'host'?: string;
221
+ }): Promise<Array<{
222
+ 'isFile': boolean;
223
+ 'isDirectory': boolean;
224
+ 'isSymbolicLink': boolean;
225
+ 'name': string;
226
+ }>>;
203
227
  /**
204
228
  * --- 完整的克隆一份数组/对象,Kebab: yes, Mutton: no ---
205
229
  * @param obj 要克隆的对象
package/lib/core.js CHANGED
@@ -56,6 +56,7 @@ exports.removeGlobal = removeGlobal;
56
56
  exports.updateCode = updateCode;
57
57
  exports.log = log;
58
58
  exports.getLog = getLog;
59
+ exports.ls = ls;
59
60
  exports.clone = clone;
60
61
  exports.debug = debug;
61
62
  exports.display = display;
@@ -66,14 +67,14 @@ exports.display = display;
66
67
  */
67
68
  const cp = __importStar(require("child_process"));
68
69
  const stream = __importStar(require("stream"));
69
- const lTime = __importStar(require("../lib/time"));
70
- const lFs = __importStar(require("../lib/fs"));
71
- const lText = __importStar(require("../lib/text"));
72
- const lNet = __importStar(require("../lib/net"));
73
- const lCrypto = __importStar(require("../lib/crypto"));
74
- const lResponse = __importStar(require("../lib/net/response"));
75
- const sCtr = __importStar(require("../sys/ctr"));
76
- const kebab = __importStar(require("../index"));
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"));
77
78
  /** --- 全局参数 --- */
78
79
  exports.globalConfig = {};
79
80
  /**
@@ -457,6 +458,9 @@ async function sendReload(hosts) {
457
458
  });
458
459
  return [];
459
460
  }
461
+ if (hosts === 'config') {
462
+ hosts = exports.globalConfig.hosts;
463
+ }
460
464
  // --- 局域网模式 ---
461
465
  const time = lTime.stamp();
462
466
  /** --- 返回成功的 host --- */
@@ -493,6 +497,9 @@ async function sendRestart(hosts) {
493
497
  });
494
498
  return [];
495
499
  }
500
+ if (hosts === 'config') {
501
+ hosts = exports.globalConfig.hosts;
502
+ }
496
503
  // --- 局域网模式 ---
497
504
  const time = lTime.stamp();
498
505
  /** --- 返回成功的 host --- */
@@ -518,7 +525,7 @@ async function sendRestart(hosts) {
518
525
  /** --- 跨进程全局变量 --- */
519
526
  exports.global = {};
520
527
  /**
521
- * --- 设置跨线程的全局变量 ---
528
+ * --- 设置跨线程/跨内网服务器的全局变量 ---
522
529
  * @param key 变量名
523
530
  * @param data 变量值
524
531
  * @param hosts 局域网列表
@@ -533,6 +540,9 @@ async function setGlobal(key, data, hosts) {
533
540
  });
534
541
  return [];
535
542
  }
543
+ if (hosts === 'config') {
544
+ hosts = exports.globalConfig.hosts;
545
+ }
536
546
  // --- 局域网模式 ---
537
547
  const time = lTime.stamp();
538
548
  /** --- 返回成功的 host --- */
@@ -556,7 +566,7 @@ async function setGlobal(key, data, hosts) {
556
566
  return rtn;
557
567
  }
558
568
  /**
559
- * --- 移除某个跨线程全局变量 ---
569
+ * --- 移除某个跨线程/跨内网服务器全局变量 ---
560
570
  * @param key 变量名
561
571
  * @param hosts 局域网列表
562
572
  */
@@ -569,8 +579,12 @@ async function removeGlobal(key, hosts) {
569
579
  * @param path 要覆盖到的路径,无所谓是否 / 开头 / 结尾,是对方 kebab 的根据路开始算起
570
580
  * @param hosts 局域网多机部署,不设置默认本机部署
571
581
  * @param config 是否自动更新 config 的 set.staticVer 为最新,默认更新
582
+ * @param strict 严格模式,只有存在的文件才会被覆盖,不存在则中途直接报错,默认为 true
572
583
  */
573
- async function updateCode(sourcePath, path, hosts, config = true) {
584
+ async function updateCode(sourcePath, path, hosts, config = true, strict = true) {
585
+ if (hosts === 'config') {
586
+ hosts = exports.globalConfig.hosts;
587
+ }
574
588
  hosts ??= ['127.0.0.1'];
575
589
  /** --- 返回成功的 host --- */
576
590
  const rtn = {};
@@ -581,6 +595,7 @@ async function updateCode(sourcePath, path, hosts, config = true) {
581
595
  }
582
596
  fd.putString('path', path);
583
597
  fd.putString('config', config ? '1' : '0');
598
+ fd.putString('strict', strict ? '1' : '0');
584
599
  const res = await lNet.post('http://' + host + ':' + exports.globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
585
600
  'action': 'code',
586
601
  'time': lTime.stamp()
@@ -609,65 +624,77 @@ async function updateCode(sourcePath, path, hosts, config = true) {
609
624
  * @param fend 文件名追加
610
625
  * @param opt 选项
611
626
  */
612
- async function log(opt, msg, fend = '') {
613
- let req;
614
- let headers;
615
- let get;
616
- let cookie;
617
- let wpath;
618
- let urlFull;
619
- let hostname;
620
- if (opt instanceof sCtr.Ctr) {
621
- req = opt.getPrototype('_req');
622
- headers = opt.getPrototype('_headers');
623
- get = opt.getPrototype('_get');
624
- cookie = opt.getPrototype('_cookie');
625
- const config = opt.getPrototype('_config');
626
- wpath = config.const.path;
627
- urlFull = config.const.urlFull;
628
- hostname = config.const.hostname;
629
- }
630
- else {
631
- req = opt.req;
632
- headers = opt.headers;
633
- get = opt.get;
634
- cookie = opt.cookie;
635
- wpath = opt.path;
636
- urlFull = opt.urlFull;
637
- hostname = opt.hostname;
638
- }
639
- if (hostname === '') {
640
- hostname = 'system';
641
- }
642
- const realIp = req?.socket.remoteAddress ?? '';
643
- const clientIp = req ? ip(headers, req) : '';
644
- const [y, m, d, h] = lTime.format(null, 'Y-m-d-H').split('-');
645
- let path = kebab.LOG_CWD + hostname + fend + '/' + y + '/' + m + '/' + d + '/';
646
- const rtn = await lFs.mkdir(path, 0o777);
647
- if (!rtn) {
648
- return;
649
- }
650
- path += h + '.csv';
651
- if (!await lFs.isFile(path)) {
652
- if (!await lFs.putContent(path, 'TIME,UNIX,URL,COOKIE,USER_AGENT,REALIP,CLIENTIP,MESSAGE\n', {
653
- 'encoding': 'utf8',
654
- 'mode': 0o777
655
- })) {
627
+ function log(opt, msg, fend = '') {
628
+ (async () => {
629
+ let req;
630
+ let headers;
631
+ let get;
632
+ let cookie;
633
+ let jwt;
634
+ let session;
635
+ let wpath;
636
+ let urlFull;
637
+ let hostname;
638
+ if (opt instanceof sCtr.Ctr) {
639
+ req = opt.getPrototype('_req');
640
+ headers = opt.getPrototype('_headers');
641
+ get = opt.getPrototype('_get');
642
+ cookie = opt.getPrototype('_cookie');
643
+ jwt = opt.getPrototype('_jwt');
644
+ session = opt.getPrototype('_session');
645
+ const config = opt.getPrototype('_config');
646
+ wpath = config.const.path;
647
+ urlFull = config.const.urlFull;
648
+ hostname = config.const.hostname;
649
+ }
650
+ else {
651
+ req = opt.req ?? null;
652
+ headers = opt.headers ?? {};
653
+ get = opt.get ?? {};
654
+ cookie = opt.cookie ?? {};
655
+ jwt = opt.jwt ?? {};
656
+ session = opt.session ?? {};
657
+ wpath = opt.path ?? '';
658
+ urlFull = opt.urlFull ?? '';
659
+ hostname = opt.hostname ?? '';
660
+ }
661
+ if (hostname === '') {
662
+ hostname = 'system';
663
+ }
664
+ const realIp = req?.socket.remoteAddress ?? '';
665
+ const clientIp = req ? ip(headers, req) : '';
666
+ const [y, m, d, h] = lTime.format(null, 'Y-m-d-H').split('-');
667
+ let path = kebab.LOG_CWD + hostname + fend + '/' + y + '/' + m + '/' + d + '/';
668
+ const rtn = await lFs.mkdir(path, 0o777);
669
+ if (!rtn) {
656
670
  return;
657
671
  }
658
- }
659
- await lFs.putContent(path, '"' +
660
- lTime.format(null, 'H:i:s') + '","' +
661
- lTime.stamp().toString() + '","' +
662
- urlFull + wpath + (Object.keys(get).length ? '?' + lText.queryStringify(get).replace(/"/g, '""') : '') + '","' +
663
- lText.queryStringify(cookie).replace(/"/g, '""') + '","' +
664
- (headers['user-agent']?.replace(/"/g, '""') ?? 'No HTTP_USER_AGENT') + '","' +
665
- realIp.replace(/"/g, '""') + '","' +
666
- clientIp.replace(/"/g, '""') + '",' +
667
- JSON.stringify(msg.replace(/"/g, '""')) + '\n', {
668
- 'encoding': 'utf8',
669
- 'mode': 0o777,
670
- 'flag': 'a'
672
+ path += h + '.csv';
673
+ if (!await lFs.isFile(path)) {
674
+ if (!await lFs.putContent(path, 'TIME,UNIX,URL,COOKIE,SESSION,JWT,USER_AGENT,REALIP,CLIENTIP,MESSAGE\n', {
675
+ 'encoding': 'utf8',
676
+ 'mode': 0o777
677
+ })) {
678
+ return;
679
+ }
680
+ }
681
+ await lFs.putContent(path, '"' +
682
+ lTime.format(null, 'H:i:s') + '","' +
683
+ lTime.stamp().toString() + '","' +
684
+ urlFull + wpath + (Object.keys(get).length ? '?' + lText.queryStringify(get).replace(/"/g, '""') : '') + '","' +
685
+ lText.queryStringify(cookie).replace(/"/g, '""') + '","' +
686
+ lText.stringifyJson(jwt).replace(/"/g, '""') + '","' +
687
+ lText.stringifyJson(session).replace(/"/g, '""') + '","' +
688
+ (headers['user-agent']?.replace(/"/g, '""') ?? 'No HTTP_USER_AGENT') + '","' +
689
+ realIp.replace(/"/g, '""') + '","' +
690
+ clientIp.replace(/"/g, '""') + '","' +
691
+ JSON.stringify(msg).slice(1, -1).replace(/"/g, '""') + '"\n', {
692
+ 'encoding': 'utf8',
693
+ 'mode': 0o777,
694
+ 'flag': 'a'
695
+ });
696
+ })().catch((e) => {
697
+ display('[CORE] [log]', e);
671
698
  });
672
699
  }
673
700
  /**
@@ -675,91 +702,59 @@ async function log(opt, msg, fend = '') {
675
702
  * @param opt 参数
676
703
  */
677
704
  async function getLog(opt) {
678
- const path = kebab.LOG_CWD + opt.host + (opt.fend ?? '') + '/' + opt.path + '.csv';
679
- if (!await lFs.isFile(path)) {
680
- return null;
681
- }
682
- /** --- 剩余 limit --- */
683
- let limit = opt.limit ?? 100;
684
- /** --- 剩余 offset --- */
685
- let offset = opt.offset ?? 0;
686
- return new Promise((resolve) => {
687
- const list = [];
688
- /** --- 当前行号 --- */
689
- let line = 0;
690
- /** --- 当前行数据 --- */
691
- let packet = '';
692
- lFs.createReadStream(path, {
693
- 'encoding': 'utf8'
694
- }).on('data', (buf) => {
695
- if (typeof buf !== 'string') {
696
- return;
697
- }
698
- while (true) {
699
- // --- 分包 ---
700
- const index = buf.indexOf('\n');
701
- if (index === -1) {
702
- // --- 本次包还没有结束 ---
703
- packet += buf;
704
- break;
705
- }
706
- // --- 本次行结束了 ---
707
- if (limit === 0) {
708
- break;
709
- }
710
- packet += buf.slice(0, index);
711
- buf = buf.slice(index + 1);
712
- ++line;
713
- // --- 先执行下本次完成的 ---
714
- if (line > 1) {
715
- if (offset === 0) {
716
- if (!opt.search || packet.includes(opt.search)) {
717
- const result = [];
718
- let currentField = '';
719
- let inQuotes = false;
720
- for (let i = 0; i < packet.length; ++i) {
721
- const char = packet[i];
722
- if (char === '"') {
723
- if (inQuotes && packet[i + 1] === '"') {
724
- currentField += '"';
725
- ++i;
726
- }
727
- else {
728
- inQuotes = !inQuotes;
729
- }
730
- }
731
- else if (char === ',' && !inQuotes) {
732
- result.push(currentField);
733
- currentField = '';
734
- }
735
- else {
736
- currentField += char;
737
- }
738
- }
739
- result.push(currentField);
740
- list.push(result);
741
- --limit;
742
- }
743
- }
744
- else {
745
- --offset;
746
- }
747
- }
748
- // --- 处理结束 ---
749
- packet = '';
750
- // --- 看看还有没有后面的粘连包 ---
751
- if (!buf.length) {
752
- // --- 没粘连包 ---
753
- break;
754
- }
755
- // --- 有粘连包 ---
756
- }
757
- }).on('end', () => {
758
- resolve(list);
759
- }).on('error', () => {
760
- resolve(false);
761
- });
705
+ opt.host ??= '127.0.0.1';
706
+ // --- 局域网模式 ---
707
+ const time = lTime.stamp();
708
+ const res = await lNet.get('http://' + opt.host + ':' + exports.globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
709
+ 'action': 'log',
710
+ 'time': time,
711
+ 'hostname': opt.hostname,
712
+ 'path': opt.path,
713
+ 'fend': opt.fend,
714
+ 'search': opt.search,
715
+ 'start': opt.start,
716
+ 'offset': opt.offset,
717
+ 'limit': opt.limit,
718
+ }), exports.globalConfig.rpcSecret), {
719
+ 'timeout': 2
762
720
  });
721
+ const content = await res.getContent();
722
+ if (!content) {
723
+ return false;
724
+ }
725
+ const str = content.toString();
726
+ const j = lText.parseJson(str);
727
+ if (!j) {
728
+ return false;
729
+ }
730
+ return j.data;
731
+ }
732
+ /**
733
+ * --- 获取目录内文件/文件夹列表 ---
734
+ * @param opt 参数
735
+ */
736
+ async function ls(opt) {
737
+ opt.host ??= '127.0.0.1';
738
+ // --- 局域网模式 ---
739
+ const time = lTime.stamp();
740
+ const res = await lNet.get('http://' + opt.host + ':' + exports.globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
741
+ 'action': 'ls',
742
+ 'time': time,
743
+ 'path': opt.path,
744
+ 'encoding': opt.encoding,
745
+ }), exports.globalConfig.rpcSecret), {
746
+ 'timeout': 2
747
+ });
748
+ const content = await res.getContent();
749
+ if (!content) {
750
+ return [];
751
+ }
752
+ const str = content.toString();
753
+ const j = lText.parseJson(str);
754
+ if (!j) {
755
+ return [];
756
+ }
757
+ return j.data;
763
758
  }
764
759
  /**
765
760
  * --- 完整的克隆一份数组/对象,Kebab: yes, Mutton: no ---
package/lib/crypto.js CHANGED
@@ -61,8 +61,8 @@ exports.uuid = uuid;
61
61
  */
62
62
  const crypto = __importStar(require("crypto"));
63
63
  // --- 库和定义 ---
64
- const lFs = __importStar(require("../lib/fs"));
65
- const lCore = __importStar(require("../lib/core"));
64
+ const lFs = __importStar(require("~/lib/fs"));
65
+ const lCore = __importStar(require("~/lib/core"));
66
66
  // --- 非对称加密 ---
67
67
  /**
68
68
  * --- 创建非对称秘钥 ---
package/lib/db.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2019-4-15 13:40
4
- * Last: 2020-4-13 15:34:45, 2022-09-12 13:10:34, 2023-5-24 18:29:38, 2024-7-11 14:37:54, 2024-8-25 00:32:53, 2024-9-22 17:30:47
4
+ * Last: 2020-4-13 15:34:45, 2022-09-12 13:10:34, 2023-5-24 18:29:38, 2024-7-11 14:37:54, 2024-8-25 00:32:53, 2024-9-22 17:30:47, 2025-8-3 20:24:03
5
5
  */
6
6
  import * as mysql2 from 'mysql2/promise';
7
- import * as ctr from '../sys/ctr';
8
- import * as types from '../types';
7
+ import * as ctr from '~/sys/ctr';
8
+ import * as types from '~/types';
9
9
  /** --- query 返回的数据 --- */
10
10
  export interface IData {
11
11
  'rows': any[] | null;