@maiyunnet/kebab 2.0.15 → 2.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * ------------------------
9
9
  */
10
10
  /** --- 当前系统版本号 --- */
11
- export declare const VER = "2.0.15";
11
+ export declare const VER = "2.0.16";
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.15';
14
+ exports.VER = '2.0.16';
15
15
  // --- 服务端用的路径 ---
16
16
  /** --- /xxx/xxx --- */
17
17
  const dirname = __dirname.replace(/\\/g, '/');
package/lib/buffer.js CHANGED
@@ -30,9 +30,7 @@ class Reader {
30
30
  }
31
31
  /** --- 读取一个 BCD 编码的字符串(每个字节表示两个数字)--- */
32
32
  readBCDString(length) {
33
- if (length === undefined) {
34
- length = this._buffer.length - this._offset;
35
- }
33
+ length ??= this._buffer.length - this._offset;
36
34
  let str = '';
37
35
  for (let i = 0; i < length; i++) {
38
36
  const byte = this._buffer.readUInt8(this._offset + i);
@@ -44,9 +42,7 @@ class Reader {
44
42
  }
45
43
  /** --- 读取普通 string --- */
46
44
  readString(length, encoding = 'utf8') {
47
- if (length === undefined) {
48
- length = this._buffer.length - this._offset;
49
- }
45
+ length ??= this._buffer.length - this._offset;
50
46
  const buf = [];
51
47
  for (let i = 0; i < length; i++) {
52
48
  const byte = this._buffer.readUInt8(this._offset + i);
@@ -60,9 +56,7 @@ class Reader {
60
56
  }
61
57
  /** --- 读取 Buffer --- */
62
58
  readBuffer(length) {
63
- if (length === undefined) {
64
- length = this._buffer.length - this._offset;
65
- }
59
+ length ??= this._buffer.length - this._offset;
66
60
  return this._buffer.subarray(this._offset, this._offset += length);
67
61
  }
68
62
  /** --- 获取完整的 buffer 长度 --- */
package/lib/s3.js CHANGED
@@ -136,7 +136,7 @@ class S3 {
136
136
  return (res.Location && res.Bucket && res.Key) ? res : false;
137
137
  }
138
138
  catch (e) {
139
- await lCore.log(this._ctr, '[putObject, s3] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
139
+ lCore.log(this._ctr, '[S3][putObject] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
140
140
  return false;
141
141
  }
142
142
  }
@@ -196,7 +196,7 @@ class S3 {
196
196
  return true;
197
197
  }
198
198
  catch (e) {
199
- await lCore.log(this._ctr, '[deleteObjects, s3] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
199
+ lCore.log(this._ctr, '[S3][deleteObjects] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
200
200
  return false;
201
201
  }
202
202
  }
@@ -215,7 +215,7 @@ class S3 {
215
215
  }
216
216
  catch (e) {
217
217
  if (e.$metadata?.httpStatusCode !== 404) {
218
- await lCore.log(this._ctr, '[headObject, s3] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
218
+ lCore.log(this._ctr, '[S3][headObject] ' + lText.stringifyJson(e.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
219
219
  }
220
220
  return false;
221
221
  }
package/lib/ws.d.ts CHANGED
@@ -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
@@ -38,6 +38,8 @@ exports.connect = connect;
38
38
  exports.createServer = createServer;
39
39
  exports.mproxy = mproxy;
40
40
  exports.rproxy = rproxy;
41
+ exports.rsocket = rsocket;
42
+ const net = __importStar(require("net"));
41
43
  // --- 第三方 ---
42
44
  const liws = __importStar(require("@litert/websocket"));
43
45
  // --- 库 ---
@@ -358,6 +360,7 @@ function bindPipe(s1, s2) {
358
360
  }
359
361
  }
360
362
  }).on('close', () => {
363
+ s2.end();
361
364
  resolve();
362
365
  });
363
366
  // --- 监听远程端的 ---
@@ -390,6 +393,7 @@ function bindPipe(s1, s2) {
390
393
  }
391
394
  }
392
395
  }).on('close', () => {
396
+ s1.end();
393
397
  resolve();
394
398
  });
395
399
  });
@@ -445,3 +449,58 @@ async function rproxy(ctr, url, opt = {}) {
445
449
  await bindPipe(socket, rsocket);
446
450
  return true;
447
451
  }
452
+ /**
453
+ * --- 反向代理,将本 websocket 连接反代到其他真正的 socket,在 ws 的 onLoad 事件中使用 ---
454
+ * @param ctr 当前控制器
455
+ * @param host 反代真实请求地址
456
+ * @param port 反代真实请求端口
457
+ * @param opt 参数
458
+ */
459
+ async function rsocket(ctr, host, port) {
460
+ return new Promise(resolve => {
461
+ /** --- 请求端产生的双向 ws --- */
462
+ const ws = ctr.getPrototype('_socket');
463
+ /** --- 对端真实 tcp socket --- */
464
+ const socket = new net.Socket();
465
+ socket.connect(port, host, () => {
466
+ // --- 连接成功 ---
467
+ // --- 监听发送端的 ---
468
+ ws.on('message', msg => {
469
+ switch (msg.opcode) {
470
+ case EOpcode.TEXT:
471
+ case EOpcode.BINARY: {
472
+ socket.write(msg.data);
473
+ break;
474
+ }
475
+ case EOpcode.CLOSE: {
476
+ socket.end();
477
+ resolve(true);
478
+ break;
479
+ }
480
+ case EOpcode.PING: {
481
+ ws.pong();
482
+ break;
483
+ }
484
+ case EOpcode.PONG: {
485
+ break;
486
+ }
487
+ default: {
488
+ // --- EOpcode.CONTINUATION ---
489
+ }
490
+ }
491
+ }).on('close', () => {
492
+ socket.end();
493
+ resolve(true);
494
+ });
495
+ // --- 监听远程端的 ---
496
+ socket.on('data', data => {
497
+ ws.writeBinary(data);
498
+ }).on('close', () => {
499
+ ws.end();
500
+ resolve(true);
501
+ });
502
+ }).on('error', () => {
503
+ resolve(false);
504
+ });
505
+ });
506
+ }
package/lib/zip.js CHANGED
@@ -182,15 +182,9 @@ class Zip {
182
182
  * @param opt 选项
183
183
  */
184
184
  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
- }
185
+ opt.hasChildren ??= false;
186
+ opt.hasDir ??= true;
187
+ opt.pathAsKey ??= false;
194
188
  if (!path) {
195
189
  path = this._path;
196
190
  }
@@ -302,7 +296,7 @@ class Zip {
302
296
  */
303
297
  _refreshList() {
304
298
  const list = {};
305
- // eslint-disable-next-line @litert/rules/disable-for-each-method
299
+ // eslint-disable-next-line @litert/disable-for-each-method
306
300
  this._zip.forEach(function (relativePath, item) {
307
301
  if (relativePath.startsWith('/')) {
308
302
  relativePath = relativePath.slice(1);
package/lib/zlib.js CHANGED
@@ -60,9 +60,7 @@ const zlib = __importStar(require("zlib"));
60
60
  * @param options 选项
61
61
  */
62
62
  function createGzip(options = {}) {
63
- if (!options.level) {
64
- options.level = 7;
65
- }
63
+ options.level ??= 7;
66
64
  return zlib.createGzip(options);
67
65
  }
68
66
  /**
@@ -76,9 +74,7 @@ function createGunzip() {
76
74
  * @param options 选项
77
75
  */
78
76
  function createDeflate(options = {}) {
79
- if (!options.level) {
80
- options.level = 7;
81
- }
77
+ options.level ??= 7;
82
78
  return zlib.createDeflate(options);
83
79
  }
84
80
  /**
@@ -92,9 +88,7 @@ function createInflate() {
92
88
  * @param options 选项
93
89
  */
94
90
  function createBrotliCompress(options = {}) {
95
- if (!options.level) {
96
- options.level = 7;
97
- }
91
+ options.level ??= 7;
98
92
  return zlib.createBrotliCompress(options);
99
93
  }
100
94
  /**
@@ -109,9 +103,7 @@ function createBrotliDecompress() {
109
103
  * @param options 选项
110
104
  */
111
105
  function createCompress(types, options = {}) {
112
- if (!options.level) {
113
- options.level = 7;
114
- }
106
+ options.level ??= 7;
115
107
  const type = getTypeByTypes(types);
116
108
  if (!type) {
117
109
  return null;
@@ -176,9 +168,7 @@ function createDecompress(types) {
176
168
  * @param options 选项
177
169
  */
178
170
  function gzip(buffer, options = {}) {
179
- if (!options.level) {
180
- options.level = 7;
181
- }
171
+ options.level ??= 7;
182
172
  return new Promise(function (resolve) {
183
173
  zlib.gzip(buffer, options, function (error, result) {
184
174
  if (error) {
@@ -212,9 +202,7 @@ function gunzip(buffer) {
212
202
  * @param options 选项
213
203
  */
214
204
  function deflate(buffer, options = {}) {
215
- if (!options.level) {
216
- options.level = 7;
217
- }
205
+ options.level ??= 7;
218
206
  return new Promise(function (resolve) {
219
207
  zlib.deflate(buffer, options, function (error, result) {
220
208
  if (error) {
@@ -248,9 +236,7 @@ function inflate(buffer) {
248
236
  * @param options 选项
249
237
  */
250
238
  function brotliCompress(buffer, options = {}) {
251
- if (!options.level) {
252
- options.level = 7;
253
- }
239
+ options.level ??= 7;
254
240
  return new Promise(function (resolve) {
255
241
  zlib.brotliCompress(buffer, options, function (error, result) {
256
242
  if (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "keywords": [
6
6
  "kebab",
package/sys/ctr.js CHANGED
@@ -147,9 +147,9 @@ class Ctr {
147
147
  if (!this._waitInfo.asyncTask.count) {
148
148
  this._waitInfo.asyncTask.resolve();
149
149
  }
150
- })().catch(async (e) => {
150
+ })().catch(e => {
151
151
  lCore.display('[ERROR][CTR][ASYNCTASK]', e);
152
- await lCore.log(this, '(ctr.asyncTask)' + text.stringifyJson(e.stack).slice(1, -1), '-error');
152
+ lCore.log(this, '[CTR][_asyncTask] ' + text.stringifyJson(e.stack).slice(1, -1), '-error');
153
153
  --this._waitInfo.asyncTask.count;
154
154
  if (!this._waitInfo.asyncTask.count) {
155
155
  this._waitInfo.asyncTask.resolve();
package/sys/mod.js CHANGED
@@ -189,15 +189,7 @@ class Mod {
189
189
  sq.insert(this._$table + (opt.index ? ('_' + opt.index) : '')).values(cs, vs);
190
190
  const r = await db.execute(sq.getSql(), sq.getData());
191
191
  if (r.packet === null) {
192
- await lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {
193
- 'path': '',
194
- 'urlFull': '',
195
- 'hostname': '',
196
- 'req': null,
197
- 'get': {},
198
- 'cookie': {},
199
- 'headers': {}
200
- }, '[insert, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
192
+ lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[insert, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
201
193
  return false;
202
194
  }
203
195
  if (r.packet.affectedRows > 0) {
@@ -230,15 +222,7 @@ class Mod {
230
222
  sq.insert(this._$table + (opt.index ? ('_' + opt.index) : '')).values(data).duplicate(update);
231
223
  const r = await db.execute(sq.getSql(), sq.getData());
232
224
  if (r.packet === null) {
233
- await lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {
234
- 'path': '',
235
- 'urlFull': '',
236
- 'hostname': '',
237
- 'req': null,
238
- 'get': {},
239
- 'cookie': {},
240
- 'headers': {}
241
- }, '[insertDuplicate, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
225
+ lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[insertDuplicate, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
242
226
  return false;
243
227
  }
244
228
  if (r.packet.affectedRows > 0) {
@@ -287,15 +271,7 @@ class Mod {
287
271
  }
288
272
  const r = await db.execute(sq.getSql(), sq.getData());
289
273
  if (r.packet === null) {
290
- await lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {
291
- 'path': '',
292
- 'urlFull': '',
293
- 'hostname': '',
294
- 'req': null,
295
- 'get': {},
296
- 'cookie': {},
297
- 'headers': {}
298
- }, '[removeByWhere, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
274
+ lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[removeByWhere, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
299
275
  return false;
300
276
  }
301
277
  if (r.packet.affectedRows > 0) {
@@ -382,15 +358,7 @@ class Mod {
382
358
  }
383
359
  const r = await db.execute(sq.getSql(), sq.getData());
384
360
  if (r.packet === null) {
385
- await lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {
386
- 'path': '',
387
- 'urlFull': '',
388
- 'hostname': '',
389
- 'req': null,
390
- 'get': {},
391
- 'cookie': {},
392
- 'headers': {}
393
- }, '[updateByWhere, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
361
+ lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[updateByWhere, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
394
362
  return false;
395
363
  }
396
364
  if (r.packet.affectedRows > 0) {
@@ -579,15 +547,7 @@ class Mod {
579
547
  sq.select(this._$primary, this._$table + (opt.index ? ('_' + opt.index) : '')).where(where);
580
548
  const r = await db.query(sq.getSql(), sq.getData());
581
549
  if (r.rows === null) {
582
- await lCore.log(opt.ctr ?? {
583
- 'path': '',
584
- 'urlFull': '',
585
- 'hostname': '',
586
- 'req': null,
587
- 'get': {},
588
- 'cookie': {},
589
- 'headers': {}
590
- }, '[primarys, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
550
+ lCore.log(opt.ctr ?? {}, '[primarys, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
591
551
  return false;
592
552
  }
593
553
  const primarys = [];
@@ -693,15 +653,7 @@ class Mod {
693
653
  }
694
654
  }
695
655
  // --- 未处理的错误 ---
696
- await lCore.log(this._ctr ?? {
697
- 'path': '',
698
- 'urlFull': '',
699
- 'hostname': '',
700
- 'req': null,
701
- 'get': {},
702
- 'cookie': {},
703
- 'headers': {}
704
- }, '[create0, mod] [' + table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
656
+ lCore.log(this._ctr ?? {}, '[create0, mod] [' + table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
705
657
  return false;
706
658
  }
707
659
  }
@@ -716,15 +668,7 @@ class Mod {
716
668
  r = await this._db.execute(this._sql.getSql(), this._sql.getData());
717
669
  if (r.error) {
718
670
  if (r.error.errno !== 1062) {
719
- await lCore.log(this._ctr ?? {
720
- 'path': '',
721
- 'urlFull': '',
722
- 'hostname': '',
723
- 'req': null,
724
- 'get': {},
725
- 'cookie': {},
726
- 'headers': {}
727
- }, '[create1, mod] [' + table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
671
+ lCore.log(this._ctr ?? {}, '[create1, mod] [' + table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
728
672
  }
729
673
  return false;
730
674
  }
@@ -751,15 +695,7 @@ class Mod {
751
695
  this._sql.replace(cstr._$table + (this._index ? ('_' + this._index[0]) : '')).values(updates);
752
696
  const r = await this._db.execute(this._sql.getSql(), this._sql.getData());
753
697
  if (r.packet === null) {
754
- await lCore.log(this._ctr ?? {
755
- 'path': '',
756
- 'urlFull': '',
757
- 'hostname': '',
758
- 'req': null,
759
- 'get': {},
760
- 'cookie': {},
761
- 'headers': {}
762
- }, '[replace, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
698
+ lCore.log(this._ctr ?? {}, '[replace, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
763
699
  return false;
764
700
  }
765
701
  if (r.packet.affectedRows > 0) {
@@ -786,15 +722,7 @@ class Mod {
786
722
  }
787
723
  const r = await this._db.query(this._sql.getSql(), this._sql.getData());
788
724
  if (r.rows === null) {
789
- await lCore.log(this._ctr ?? {
790
- 'path': '',
791
- 'urlFull': '',
792
- 'hostname': '',
793
- 'req': null,
794
- 'get': {},
795
- 'cookie': {},
796
- 'headers': {}
797
- }, '[refresh, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
725
+ lCore.log(this._ctr ?? {}, '[refresh, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
798
726
  return false;
799
727
  }
800
728
  if (r.rows.length === 0) {
@@ -824,15 +752,7 @@ class Mod {
824
752
  }]);
825
753
  const r = await this._db.execute(this._sql.getSql(), this._sql.getData());
826
754
  if (r.packet === null) {
827
- await lCore.log(this._ctr ?? {
828
- 'path': '',
829
- 'urlFull': '',
830
- 'hostname': '',
831
- 'req': null,
832
- 'get': {},
833
- 'cookie': {},
834
- 'headers': {}
835
- }, '[save, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
755
+ lCore.log(this._ctr ?? {}, '[save, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
836
756
  return false;
837
757
  }
838
758
  if (r.packet.affectedRows > 0) {
@@ -865,15 +785,7 @@ class Mod {
865
785
  }
866
786
  const r = await this._db.execute(this._sql.getSql(), this._sql.getData());
867
787
  if (r.packet === null) {
868
- await lCore.log(this._ctr ?? {
869
- 'path': '',
870
- 'urlFull': '',
871
- 'hostname': '',
872
- 'req': null,
873
- 'get': {},
874
- 'cookie': {},
875
- 'headers': {}
876
- }, '[remove, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
788
+ lCore.log(this._ctr ?? {}, '[remove, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
877
789
  return false;
878
790
  }
879
791
  if (r.packet.affectedRows > 0) {
@@ -895,15 +807,7 @@ class Mod {
895
807
  }
896
808
  const r = await this._db.query(this._sql.getSql(), this._sql.getData());
897
809
  if (r.rows === null) {
898
- await lCore.log(this._ctr ?? {
899
- 'path': '',
900
- 'urlFull': '',
901
- 'hostname': '',
902
- 'req': null,
903
- 'get': {},
904
- 'cookie': {},
905
- 'headers': {}
906
- }, '[first, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
810
+ lCore.log(this._ctr ?? {}, '[first, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
907
811
  return false;
908
812
  }
909
813
  if (r.rows.length === 0) {
@@ -1034,15 +938,7 @@ class Mod {
1034
938
  const lsql = sql.replace(/ LIMIT [0-9 ,]/g, ` LIMIT ${cz}, ${remain}`);
1035
939
  const r = await this._db.query(lsql, this._sql.getData());
1036
940
  if (r.rows === null) {
1037
- await lCore.log(this._ctr ?? {
1038
- 'path': '',
1039
- 'urlFull': '',
1040
- 'hostname': '',
1041
- 'req': null,
1042
- 'get': {},
1043
- 'cookie': {},
1044
- 'headers': {}
1045
- }, '[all, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
941
+ lCore.log(this._ctr ?? {}, '[all, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1046
942
  return false;
1047
943
  }
1048
944
  if (key) {
@@ -1078,15 +974,7 @@ class Mod {
1078
974
  const contain = this._contain ? lCore.clone(this._contain.list) : null;
1079
975
  const r = await this._db.query(this._sql.getSql(), this._sql.getData());
1080
976
  if (r.rows === null) {
1081
- await lCore.log(this._ctr ?? {
1082
- 'path': '',
1083
- 'urlFull': '',
1084
- 'hostname': '',
1085
- 'req': null,
1086
- 'get': {},
1087
- 'cookie': {},
1088
- 'headers': {}
1089
- }, '[all, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
977
+ lCore.log(this._ctr ?? {}, '[all, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1090
978
  return false;
1091
979
  }
1092
980
  // --- 检查没被查到的必包含项 ---
@@ -1211,15 +1099,7 @@ class Mod {
1211
1099
  const lsql = sql.replace(/ LIMIT [0-9 ,]+/g, ` LIMIT ${cz}, ${remain}`);
1212
1100
  const r = await this._db.query(lsql, this._sql.getData());
1213
1101
  if (r.rows === null) {
1214
- await lCore.log(this._ctr ?? {
1215
- 'path': '',
1216
- 'urlFull': '',
1217
- 'hostname': '',
1218
- 'req': null,
1219
- 'get': {},
1220
- 'cookie': {},
1221
- 'headers': {}
1222
- }, '[allArray, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1102
+ lCore.log(this._ctr ?? {}, '[allArray, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1223
1103
  return false;
1224
1104
  }
1225
1105
  if (key) {
@@ -1241,15 +1121,7 @@ class Mod {
1241
1121
  const contain = this._contain ? lCore.clone(this._contain.list) : null;
1242
1122
  const r = await this._db.query(this._sql.getSql(), this._sql.getData());
1243
1123
  if (r.rows === null) {
1244
- await lCore.log(this._ctr ?? {
1245
- 'path': '',
1246
- 'urlFull': '',
1247
- 'hostname': '',
1248
- 'req': null,
1249
- 'get': {},
1250
- 'cookie': {},
1251
- 'headers': {}
1252
- }, '[allArray, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1124
+ lCore.log(this._ctr ?? {}, '[allArray, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1253
1125
  return false;
1254
1126
  }
1255
1127
  // --- 检查没被查到的必包含项 ---
@@ -1298,15 +1170,7 @@ class Mod {
1298
1170
  async explain(all = false) {
1299
1171
  const r = await this._db.query('EXPLAIN ' + this._sql.getSql(), this._sql.getData());
1300
1172
  if (r.rows === null) {
1301
- await lCore.log(this._ctr ?? {
1302
- 'path': '',
1303
- 'urlFull': '',
1304
- 'hostname': '',
1305
- 'req': null,
1306
- 'get': {},
1307
- 'cookie': {},
1308
- 'headers': {}
1309
- }, '[explain, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1173
+ lCore.log(this._ctr ?? {}, '[explain, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1310
1174
  return false;
1311
1175
  }
1312
1176
  if (!r.rows[0]) {
@@ -1341,15 +1205,7 @@ class Mod {
1341
1205
  const sql = this._formatTotal(this._sql.getSql(), f);
1342
1206
  const r = await this._db.query(sql, this._sql.getData());
1343
1207
  if (r.rows === null) {
1344
- await lCore.log(this._ctr ?? {
1345
- 'path': '',
1346
- 'urlFull': '',
1347
- 'hostname': '',
1348
- 'req': null,
1349
- 'get': {},
1350
- 'cookie': {},
1351
- 'headers': {}
1352
- }, '[total, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1208
+ lCore.log(this._ctr ?? {}, '[total, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1353
1209
  return 0;
1354
1210
  }
1355
1211
  let count = 0;
@@ -1365,15 +1221,7 @@ class Mod {
1365
1221
  const sql = this._sql.getSql().replace(/SELECT .+? FROM/, 'SELECT COUNT(*) AS `count` FROM');
1366
1222
  const r = await this._db.query(sql, this._sql.getData());
1367
1223
  if (r.rows === null) {
1368
- await lCore.log(this._ctr ?? {
1369
- 'path': '',
1370
- 'urlFull': '',
1371
- 'hostname': '',
1372
- 'req': null,
1373
- 'get': {},
1374
- 'cookie': {},
1375
- 'headers': {}
1376
- }, '[count, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1224
+ lCore.log(this._ctr ?? {}, '[count, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1377
1225
  return 0;
1378
1226
  }
1379
1227
  let count = 0;
package/sys/route.js CHANGED
@@ -299,6 +299,8 @@ async function run(data) {
299
299
  let wsSocket;
300
300
  try {
301
301
  const options = await cctr.onUpgrade();
302
+ // --- 默认无消息发送 3 分钟 ---
303
+ options.timeout ??= 60_000 * 3;
302
304
  wsSocket = lWs.createServer(data.req, data.socket, options);
303
305
  cctr.setPrototype('_socket', wsSocket);
304
306
  }
@@ -0,0 +1,4 @@
1
+ import * as sCtr from '~/sys/ctr';
2
+ export default class extends sCtr.Ctr {
3
+ onLoad(): Promise<boolean>;
4
+ }
@@ -0,0 +1,47 @@
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
+ const sCtr = __importStar(require("~/sys/ctr"));
37
+ const lWs = __importStar(require("~/lib/ws"));
38
+ class default_1 extends sCtr.Ctr {
39
+ async onLoad() {
40
+ console.log('WebSocket rsocket test onLoad.');
41
+ if (await lWs.rsocket(this, '192.168.31.99', 5900)) {
42
+ return false;
43
+ }
44
+ return true;
45
+ }
46
+ }
47
+ exports.default = default_1;
@@ -1,6 +1,11 @@
1
1
  import * as sCtr from '~/sys/ctr';
2
+ import * as http from 'http';
2
3
  export default class extends sCtr.Ctr {
3
4
  private _nick;
5
+ onUpgrade(): {
6
+ 'headers'?: http.OutgoingHttpHeaders;
7
+ 'timeout'?: number;
8
+ };
4
9
  onLoad(): boolean;
5
10
  onData(data: Buffer | string): string;
6
11
  onClose(): void;
@@ -40,6 +40,11 @@ class default_1 extends sCtr.Ctr {
40
40
  super(...arguments);
41
41
  this._nick = '';
42
42
  }
43
+ onUpgrade() {
44
+ return {
45
+ 'timeout': 60_000 * 2,
46
+ };
47
+ }
43
48
  onLoad() {
44
49
  console.log('WebSocket test onLoad.');
45
50
  setTimeout(() => {
@@ -59,7 +64,8 @@ class default_1 extends sCtr.Ctr {
59
64
  return 'Base64: ' + lCrypto.base64Encode(data);
60
65
  }
61
66
  // --- 用户消息 ---
62
- console.log('[' + Date.now() + '] WebSocket test onData, data: ' + data);
67
+ const date = new Date();
68
+ console.log('[' + date.getHours().toString().padStart(2, '0') + ':' + date.getMinutes().toString().padStart(2, '0') + ':' + date.getSeconds().toString().padStart(2, '0') + '] WebSocket test onData, data: ' + data);
63
69
  return '<b>' + this._nick + ':</b> ' + data;
64
70
  }
65
71
  onClose() {