@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/time.js CHANGED
@@ -1,55 +1,15 @@
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.Time = exports.YEAR = exports.DAY = exports.HOUR = void 0;
37
- exports.get = get;
38
- exports.stamp = stamp;
39
- exports.isMs = isMs;
40
- exports.format = format;
41
1
  /**
42
2
  * Project: Kebab, User: JianSuoQiYue
43
3
  * Date: 2019-6-6 12:04:15
44
4
  * Last: 2020-3-29 23:41:21, 2024-1-18 17:16:50, 2024-8-5 10:55:21
45
5
  */
46
- const sCtr = __importStar(require("~/sys/ctr"));
6
+ import * as sCtr from '../sys/ctr.js';
47
7
  /** --- 一小时的秒数 --- */
48
- exports.HOUR = 3600;
8
+ export const HOUR = 3600;
49
9
  /** --- 一天的秒数 --- */
50
- exports.DAY = 86400;
10
+ export const DAY = 86400;
51
11
  /** --- 一年(365 天) */
52
- exports.YEAR = 31536000;
12
+ export const YEAR = 31536000;
53
13
  /** --- 星期名 --- */
54
14
  const dayNames = [
55
15
  ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
@@ -60,7 +20,7 @@ const monthNames = [
60
20
  ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
61
21
  ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
62
22
  ];
63
- class Time {
23
+ export class Time {
64
24
  /**
65
25
  * --- 构造函数 ---
66
26
  * @param opt
@@ -125,12 +85,11 @@ class Time {
125
85
  return stamp(this._date);
126
86
  }
127
87
  }
128
- exports.Time = Time;
129
88
  /**
130
89
  * --- 创建获取一个时间对象 ---
131
90
  * @param opt
132
91
  */
133
- function get(ctr, opt = {}) {
92
+ export function get(ctr, opt = {}) {
134
93
  return new Time(ctr, opt);
135
94
  }
136
95
  /**
@@ -138,7 +97,7 @@ function get(ctr, opt = {}) {
138
97
  * @param date Date 对象可选
139
98
  * @param zone 时区小时或 ctr 对象,如 8,设置 null 则以系统时区为准
140
99
  */
141
- function stamp(date, zone) {
100
+ export function stamp(date, zone) {
142
101
  if (date) {
143
102
  if (date instanceof Date) {
144
103
  return Math.floor(date.getTime() / 1000);
@@ -166,7 +125,7 @@ function stamp(date, zone) {
166
125
  * --- 是否是毫秒 ---
167
126
  * @param time 要判断的时间戳
168
127
  */
169
- function isMs(time) {
128
+ export function isMs(time) {
170
129
  return time > 1000000000000 ? true : false;
171
130
  }
172
131
  /**
@@ -175,7 +134,7 @@ function isMs(time) {
175
134
  * @param f 转换格式
176
135
  * @param date 时间对象或秒/毫秒级数字,如果是秒请乘以 1000
177
136
  */
178
- function format(zone, f, date) {
137
+ export function format(zone, f, date) {
179
138
  const over = [];
180
139
  if (date === undefined) {
181
140
  date = new Date();
@@ -189,6 +148,7 @@ function format(zone, f, date) {
189
148
  else if (zone instanceof sCtr.Ctr) {
190
149
  zone = zone.getPrototype('_config').set.timezone;
191
150
  }
151
+ zone ??= (-date.getTimezoneOffset()) / 60;
192
152
  if (zone !== 0) {
193
153
  date = new Date(date.getTime() + zone * 60 * 60 * 1000);
194
154
  }
@@ -1,4 +1,4 @@
1
- import * as sCtr from '~/sys/ctr';
1
+ import * as sCtr from '../sys/ctr.js';
2
2
  /**
3
3
  * 0. CloudFlare:https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
4
4
  * 1. 腾讯云:https://cloud.tencent.com/document/product/1110/36926
package/lib/turnstile.js CHANGED
@@ -1,60 +1,23 @@
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.EFACTORY = void 0;
37
- exports.verify = verify;
38
1
  /**
39
2
  * Project: Kebab, User: JianSuoQiYue
40
3
  * Date: 2025-6-11
41
4
  * Last: 2025-6-11 21:50:31
42
5
  */
43
- const tc = __importStar(require("tencentcloud-sdk-nodejs"));
6
+ import * as tc from 'tencentcloud-sdk-nodejs';
44
7
  // --- 库和定义 ---
45
- const lNet = __importStar(require("~/lib/net"));
46
- const lText = __importStar(require("~/lib/text"));
8
+ import * as lNet from '../lib/net.js';
9
+ import * as lText from '../lib/text.js';
47
10
  /**
48
11
  * 0. CloudFlare:https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
49
12
  * 1. 腾讯云:https://cloud.tencent.com/document/product/1110/36926
50
13
  */
51
14
  /** --- 厂家 --- */
52
- var EFACTORY;
15
+ export var EFACTORY;
53
16
  (function (EFACTORY) {
54
17
  EFACTORY[EFACTORY["CLOUDFLARE"] = 0] = "CLOUDFLARE";
55
18
  EFACTORY[EFACTORY["TENCENT"] = 1] = "TENCENT";
56
- })(EFACTORY || (exports.EFACTORY = EFACTORY = {}));
57
- async function verify(ctr, opt) {
19
+ })(EFACTORY || (EFACTORY = {}));
20
+ export async function verify(ctr, opt) {
58
21
  const config = ctr.getPrototype('_config');
59
22
  switch (opt.factory) {
60
23
  case EFACTORY.CLOUDFLARE: {
package/lib/ws.d.ts CHANGED
@@ -5,8 +5,8 @@
5
5
  */
6
6
  import * as http from 'http';
7
7
  import * as net from 'net';
8
- import * as types from '~/types';
9
- import * as sCtr from '~/sys/ctr';
8
+ import * as types from '../types/index.js';
9
+ import * as sCtr from '../sys/ctr.js';
10
10
  /** --- 一般用 SIMPLE --- */
11
11
  export declare enum EFrameReceiveMode {
12
12
  STANDARD = 0,
@@ -153,3 +153,11 @@ export declare function mproxy(ctr: sCtr.Ctr, auth: string, opt?: IMproxyOptions
153
153
  * @param opt 参数
154
154
  */
155
155
  export declare function rproxy(ctr: sCtr.Ctr, url: string, opt?: IRproxyOptions): Promise<boolean>;
156
+ /**
157
+ * --- 反向代理,将本 websocket 连接反代到其他真正的 socket,在 ws 的 onLoad 事件中使用 ---
158
+ * @param ctr 当前控制器
159
+ * @param host 反代真实请求地址
160
+ * @param port 反代真实请求端口
161
+ * @param opt 参数
162
+ */
163
+ export declare function rsocket(ctr: sCtr.Ctr, host: string, port: number): Promise<boolean>;
package/lib/ws.js CHANGED
@@ -1,57 +1,18 @@
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.Socket = exports.EOpcode = exports.EFrameReceiveMode = void 0;
37
- exports.connect = connect;
38
- exports.createServer = createServer;
39
- exports.mproxy = mproxy;
40
- exports.rproxy = rproxy;
1
+ import * as net from 'net';
41
2
  // --- 第三方 ---
42
- const liws = __importStar(require("@litert/websocket"));
3
+ import * as liws from '@litert/websocket';
43
4
  // --- 库 ---
44
- const lText = __importStar(require("~/lib/text"));
45
- const lNet = __importStar(require("~/lib/net"));
5
+ import * as lText from '../lib/text.js';
6
+ import * as lNet from '../lib/net.js';
46
7
  /** --- 一般用 SIMPLE --- */
47
- var EFrameReceiveMode;
8
+ export var EFrameReceiveMode;
48
9
  (function (EFrameReceiveMode) {
49
10
  EFrameReceiveMode[EFrameReceiveMode["STANDARD"] = 0] = "STANDARD";
50
11
  EFrameReceiveMode[EFrameReceiveMode["LITE"] = 1] = "LITE";
51
12
  EFrameReceiveMode[EFrameReceiveMode["SIMPLE"] = 2] = "SIMPLE";
52
- })(EFrameReceiveMode || (exports.EFrameReceiveMode = EFrameReceiveMode = {}));
13
+ })(EFrameReceiveMode || (EFrameReceiveMode = {}));
53
14
  /** --- OPCODE --- */
54
- var EOpcode;
15
+ export var EOpcode;
55
16
  (function (EOpcode) {
56
17
  EOpcode[EOpcode["CONTINUATION"] = 0] = "CONTINUATION";
57
18
  EOpcode[EOpcode["TEXT"] = 1] = "TEXT";
@@ -59,9 +20,9 @@ var EOpcode;
59
20
  EOpcode[EOpcode["CLOSE"] = 8] = "CLOSE";
60
21
  EOpcode[EOpcode["PING"] = 9] = "PING";
61
22
  EOpcode[EOpcode["PONG"] = 10] = "PONG";
62
- })(EOpcode || (exports.EOpcode = EOpcode = {}));
23
+ })(EOpcode || (EOpcode = {}));
63
24
  const liwsServer = liws.createServer();
64
- class Socket {
25
+ export class Socket {
65
26
  constructor(request, socket, options = {}) {
66
27
  /** --- 还未开启监听时来的数据将存在这里 --- */
67
28
  this._waitMsg = [];
@@ -303,13 +264,12 @@ class Socket {
303
264
  }
304
265
  }
305
266
  }
306
- exports.Socket = Socket;
307
267
  /**
308
268
  * --- 创建一个 ws 客户端发起 ws 请求 ---
309
269
  * @param u 以 ws, wss 开头的地址
310
270
  * @param opt 参数
311
271
  */
312
- function connect(u, opt = {}) {
272
+ export function connect(u, opt = {}) {
313
273
  const s = new Socket();
314
274
  return s.connect(u, opt);
315
275
  }
@@ -318,7 +278,7 @@ function connect(u, opt = {}) {
318
278
  * @param request Http 请求端
319
279
  * @param socket 响应双向 socket
320
280
  */
321
- function createServer(request, socket, options = {}) {
281
+ export function createServer(request, socket, options = {}) {
322
282
  return new Socket(request, socket, options);
323
283
  }
324
284
  /**
@@ -358,6 +318,7 @@ function bindPipe(s1, s2) {
358
318
  }
359
319
  }
360
320
  }).on('close', () => {
321
+ s2.end();
361
322
  resolve();
362
323
  });
363
324
  // --- 监听远程端的 ---
@@ -390,6 +351,7 @@ function bindPipe(s1, s2) {
390
351
  }
391
352
  }
392
353
  }).on('close', () => {
354
+ s1.end();
393
355
  resolve();
394
356
  });
395
357
  });
@@ -401,7 +363,7 @@ function bindPipe(s1, s2) {
401
363
  * @param auth 校验字符串,读取 get 的 auth 和本参数做比对
402
364
  * @param opt 参数
403
365
  */
404
- async function mproxy(ctr, auth, opt = {}) {
366
+ export async function mproxy(ctr, auth, opt = {}) {
405
367
  const req = ctr.getPrototype('_req');
406
368
  /** --- 请求端产生的双向 socket --- */
407
369
  const socket = ctr.getPrototype('_socket');
@@ -430,7 +392,7 @@ async function mproxy(ctr, auth, opt = {}) {
430
392
  * @param url 反代真实请求地址,如有 get 需要自行添加
431
393
  * @param opt 参数
432
394
  */
433
- async function rproxy(ctr, url, opt = {}) {
395
+ export async function rproxy(ctr, url, opt = {}) {
434
396
  const req = ctr.getPrototype('_req');
435
397
  /** --- 请求端产生的双向 socket --- */
436
398
  const socket = ctr.getPrototype('_socket');
@@ -445,3 +407,58 @@ async function rproxy(ctr, url, opt = {}) {
445
407
  await bindPipe(socket, rsocket);
446
408
  return true;
447
409
  }
410
+ /**
411
+ * --- 反向代理,将本 websocket 连接反代到其他真正的 socket,在 ws 的 onLoad 事件中使用 ---
412
+ * @param ctr 当前控制器
413
+ * @param host 反代真实请求地址
414
+ * @param port 反代真实请求端口
415
+ * @param opt 参数
416
+ */
417
+ export async function rsocket(ctr, host, port) {
418
+ return new Promise(resolve => {
419
+ /** --- 请求端产生的双向 ws --- */
420
+ const ws = ctr.getPrototype('_socket');
421
+ /** --- 对端真实 tcp socket --- */
422
+ const socket = new net.Socket();
423
+ socket.connect(port, host, () => {
424
+ // --- 连接成功 ---
425
+ // --- 监听发送端的 ---
426
+ ws.on('message', msg => {
427
+ switch (msg.opcode) {
428
+ case EOpcode.TEXT:
429
+ case EOpcode.BINARY: {
430
+ socket.write(msg.data);
431
+ break;
432
+ }
433
+ case EOpcode.CLOSE: {
434
+ socket.end();
435
+ resolve(true);
436
+ break;
437
+ }
438
+ case EOpcode.PING: {
439
+ ws.pong();
440
+ break;
441
+ }
442
+ case EOpcode.PONG: {
443
+ break;
444
+ }
445
+ default: {
446
+ // --- EOpcode.CONTINUATION ---
447
+ }
448
+ }
449
+ }).on('close', () => {
450
+ socket.end();
451
+ resolve(true);
452
+ });
453
+ // --- 监听远程端的 ---
454
+ socket.on('data', data => {
455
+ ws.writeBinary(data);
456
+ }).on('close', () => {
457
+ ws.end();
458
+ resolve(true);
459
+ });
460
+ }).on('error', () => {
461
+ resolve(false);
462
+ });
463
+ });
464
+ }
package/lib/zip.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import jszip from 'jszip';
2
- import * as types from '~/types';
2
+ import * as types from '../types/index.js';
3
3
  /**
4
4
  * --- 本库主要用于读取 zip,请尽量不要用来写入 zip,尤其是大文件 zip ---
5
5
  */
package/lib/zip.js CHANGED
@@ -1,50 +1,10 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.Zip = void 0;
40
- exports.get = get;
41
- const jszip_1 = __importDefault(require("jszip"));
42
- const mime = __importStar(require("@litert/mime"));
43
- const lText = __importStar(require("~/lib/text"));
1
+ import jszip from 'jszip';
2
+ import * as mime from '@litert/mime';
3
+ import * as lText from '../lib/text.js';
44
4
  /**
45
5
  * --- 本库主要用于读取 zip,请尽量不要用来写入 zip,尤其是大文件 zip ---
46
6
  */
47
- class Zip {
7
+ export class Zip {
48
8
  constructor(zip) {
49
9
  /** --- 当前路径,以 / 开头以 / 结尾 --- */
50
10
  this._path = '/';
@@ -182,15 +142,9 @@ class Zip {
182
142
  * @param opt 选项
183
143
  */
184
144
  readDir(path, opt = {}) {
185
- if (opt.hasChildren === undefined) {
186
- opt.hasChildren = false;
187
- }
188
- if (opt.hasDir === undefined) {
189
- opt.hasDir = true;
190
- }
191
- if (opt.pathAsKey === undefined) {
192
- opt.pathAsKey = false;
193
- }
145
+ opt.hasChildren ??= false;
146
+ opt.hasDir ??= true;
147
+ opt.pathAsKey ??= false;
194
148
  if (!path) {
195
149
  path = this._path;
196
150
  }
@@ -302,7 +256,7 @@ class Zip {
302
256
  */
303
257
  _refreshList() {
304
258
  const list = {};
305
- // eslint-disable-next-line @litert/rules/disable-for-each-method
259
+ // eslint-disable-next-line @litert/disable-for-each-method
306
260
  this._zip.forEach(function (relativePath, item) {
307
261
  if (relativePath.startsWith('/')) {
308
262
  relativePath = relativePath.slice(1);
@@ -435,13 +389,12 @@ class Zip {
435
389
  });
436
390
  }
437
391
  }
438
- exports.Zip = Zip;
439
392
  /**
440
393
  * --- 获取 zip 对象 ---
441
394
  * @param data 对象数据
442
395
  */
443
- async function get(data) {
444
- const z = (0, jszip_1.default)();
396
+ export async function get(data) {
397
+ const z = jszip();
445
398
  try {
446
399
  if (data) {
447
400
  await z.loadAsync(data);