@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.
- package/README.md +1 -5
- package/index.d.ts +1 -1
- package/index.js +16 -18
- package/lib/buffer.js +7 -20
- package/lib/captcha.js +6 -44
- package/lib/consistent.js +8 -51
- package/lib/core.d.ts +4 -4
- package/lib/core.js +70 -132
- package/lib/crypto.js +43 -99
- package/lib/db.d.ts +5 -5
- package/lib/db.js +31 -68
- package/lib/dns.d.ts +1 -1
- package/lib/dns.js +12 -50
- package/lib/fs.js +26 -81
- package/lib/jwt.d.ts +3 -3
- package/lib/jwt.js +9 -50
- package/lib/kv.d.ts +4 -4
- package/lib/kv.js +31 -69
- package/lib/lan.js +4 -41
- package/lib/net/cacert.pem +78 -2
- package/lib/net/formdata.js +5 -42
- package/lib/net/request.d.ts +2 -2
- package/lib/net/request.js +3 -42
- package/lib/net/response.d.ts +1 -1
- package/lib/net/response.js +1 -5
- package/lib/net.d.ts +5 -5
- package/lib/net.js +24 -73
- package/lib/s3.d.ts +1 -1
- package/lib/s3.js +23 -62
- package/lib/scan.d.ts +3 -3
- package/lib/scan.js +10 -50
- package/lib/session.d.ts +3 -3
- package/lib/session.js +9 -46
- package/lib/sql.d.ts +2 -2
- package/lib/sql.js +9 -50
- package/lib/ssh/sftp.js +5 -46
- package/lib/ssh/shell.js +2 -39
- package/lib/ssh.d.ts +2 -2
- package/lib/ssh.js +5 -43
- package/lib/text.d.ts +1 -1
- package/lib/text.js +40 -104
- package/lib/time.d.ts +1 -1
- package/lib/time.js +10 -50
- package/lib/turnstile.d.ts +1 -1
- package/lib/turnstile.js +6 -43
- package/lib/ws.d.ts +10 -2
- package/lib/ws.js +70 -53
- package/lib/zip.d.ts +1 -1
- package/lib/zip.js +10 -57
- package/lib/zlib.js +24 -89
- package/main.js +6 -44
- package/package.json +9 -8
- package/sys/child.js +10 -45
- package/sys/cmd.js +8 -43
- package/sys/ctr.d.ts +5 -5
- package/sys/ctr.js +11 -49
- package/sys/master.js +11 -46
- package/sys/mod.d.ts +9 -5
- package/sys/mod.js +28 -214
- package/sys/route.d.ts +2 -2
- package/sys/route.js +26 -64
- package/types/index.d.ts +1 -0
- package/www/example/ctr/main.d.ts +1 -1
- package/www/example/ctr/main.js +2 -38
- package/www/example/ctr/middle.d.ts +2 -2
- package/www/example/ctr/middle.js +2 -38
- package/www/example/ctr/test.d.ts +2 -2
- package/www/example/ctr/test.js +65 -72
- package/www/example/mod/test.d.ts +2 -2
- package/www/example/mod/test.js +4 -42
- package/www/example/mod/testdata.d.ts +1 -1
- package/www/example/mod/testdata.js +3 -8
- package/www/example/ws/mproxy.d.ts +1 -1
- package/www/example/ws/mproxy.js +6 -41
- package/www/example/ws/rproxy.d.ts +1 -1
- package/www/example/ws/rproxy.js +5 -40
- package/www/example/ws/rsocket.d.ts +4 -0
- package/www/example/ws/rsocket.js +12 -0
- package/www/example/ws/test.d.ts +6 -1
- package/www/example/ws/test.js +13 -42
- package/eslint.config.js +0 -22
package/sys/mod.js
CHANGED
|
@@ -1,48 +1,13 @@
|
|
|
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
1
|
/**
|
|
37
2
|
* Project: Mutton, User: JianSuoQiYue
|
|
38
3
|
* Date: 2019-6-4 21:35
|
|
39
4
|
* Last: 2020-4-14 13:33:51, 2022-07-23 16:01:34, 2022-09-06 22:59:26, 2023-5-24 19:11:37, 2023-6-13 21:47:58, 2023-7-10 18:54:03, 2023-8-23 17:03:16, 2023-12-11 15:21:22, 2023-12-20 23:12:03, 2024-3-8 16:05:29, 2024-3-20 19:58:15, 2024-8-11 21:14:54, 2024-10-5 14:00:22, 2024-12-14 19:58:34
|
|
40
5
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
6
|
+
import * as lSql from '../lib/sql.js';
|
|
7
|
+
import * as lTime from '../lib/time.js';
|
|
8
|
+
import * as lCore from '../lib/core.js';
|
|
9
|
+
import * as lText from '../lib/text.js';
|
|
10
|
+
import * as sCtr from '../sys/ctr.js';
|
|
46
11
|
/** --- 条数列表 --- */
|
|
47
12
|
class Rows {
|
|
48
13
|
constructor(initialItems = []) {
|
|
@@ -189,15 +154,7 @@ class Mod {
|
|
|
189
154
|
sq.insert(this._$table + (opt.index ? ('_' + opt.index) : '')).values(cs, vs);
|
|
190
155
|
const r = await db.execute(sq.getSql(), sq.getData());
|
|
191
156
|
if (r.packet === null) {
|
|
192
|
-
|
|
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');
|
|
157
|
+
lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[insert, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
|
|
201
158
|
return false;
|
|
202
159
|
}
|
|
203
160
|
if (r.packet.affectedRows > 0) {
|
|
@@ -230,15 +187,7 @@ class Mod {
|
|
|
230
187
|
sq.insert(this._$table + (opt.index ? ('_' + opt.index) : '')).values(data).duplicate(update);
|
|
231
188
|
const r = await db.execute(sq.getSql(), sq.getData());
|
|
232
189
|
if (r.packet === null) {
|
|
233
|
-
|
|
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');
|
|
190
|
+
lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[insertDuplicate, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
242
191
|
return false;
|
|
243
192
|
}
|
|
244
193
|
if (r.packet.affectedRows > 0) {
|
|
@@ -287,15 +236,7 @@ class Mod {
|
|
|
287
236
|
}
|
|
288
237
|
const r = await db.execute(sq.getSql(), sq.getData());
|
|
289
238
|
if (r.packet === null) {
|
|
290
|
-
|
|
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');
|
|
239
|
+
lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[removeByWhere, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
299
240
|
return false;
|
|
300
241
|
}
|
|
301
242
|
if (r.packet.affectedRows > 0) {
|
|
@@ -382,15 +323,7 @@ class Mod {
|
|
|
382
323
|
}
|
|
383
324
|
const r = await db.execute(sq.getSql(), sq.getData());
|
|
384
325
|
if (r.packet === null) {
|
|
385
|
-
|
|
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');
|
|
326
|
+
lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[updateByWhere, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
394
327
|
return false;
|
|
395
328
|
}
|
|
396
329
|
if (r.packet.affectedRows > 0) {
|
|
@@ -579,15 +512,7 @@ class Mod {
|
|
|
579
512
|
sq.select(this._$primary, this._$table + (opt.index ? ('_' + opt.index) : '')).where(where);
|
|
580
513
|
const r = await db.query(sq.getSql(), sq.getData());
|
|
581
514
|
if (r.rows === null) {
|
|
582
|
-
|
|
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');
|
|
515
|
+
lCore.log(opt.ctr ?? {}, '[primarys, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
591
516
|
return false;
|
|
592
517
|
}
|
|
593
518
|
const primarys = [];
|
|
@@ -693,15 +618,7 @@ class Mod {
|
|
|
693
618
|
}
|
|
694
619
|
}
|
|
695
620
|
// --- 未处理的错误 ---
|
|
696
|
-
|
|
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');
|
|
621
|
+
lCore.log(this._ctr ?? {}, '[create0, mod] [' + table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
705
622
|
return false;
|
|
706
623
|
}
|
|
707
624
|
}
|
|
@@ -716,15 +633,7 @@ class Mod {
|
|
|
716
633
|
r = await this._db.execute(this._sql.getSql(), this._sql.getData());
|
|
717
634
|
if (r.error) {
|
|
718
635
|
if (r.error.errno !== 1062) {
|
|
719
|
-
|
|
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');
|
|
636
|
+
lCore.log(this._ctr ?? {}, '[create1, mod] [' + table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
728
637
|
}
|
|
729
638
|
return false;
|
|
730
639
|
}
|
|
@@ -751,15 +660,7 @@ class Mod {
|
|
|
751
660
|
this._sql.replace(cstr._$table + (this._index ? ('_' + this._index[0]) : '')).values(updates);
|
|
752
661
|
const r = await this._db.execute(this._sql.getSql(), this._sql.getData());
|
|
753
662
|
if (r.packet === null) {
|
|
754
|
-
|
|
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');
|
|
663
|
+
lCore.log(this._ctr ?? {}, '[replace, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
763
664
|
return false;
|
|
764
665
|
}
|
|
765
666
|
if (r.packet.affectedRows > 0) {
|
|
@@ -786,15 +687,7 @@ class Mod {
|
|
|
786
687
|
}
|
|
787
688
|
const r = await this._db.query(this._sql.getSql(), this._sql.getData());
|
|
788
689
|
if (r.rows === null) {
|
|
789
|
-
|
|
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');
|
|
690
|
+
lCore.log(this._ctr ?? {}, '[refresh, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
798
691
|
return false;
|
|
799
692
|
}
|
|
800
693
|
if (r.rows.length === 0) {
|
|
@@ -824,15 +717,7 @@ class Mod {
|
|
|
824
717
|
}]);
|
|
825
718
|
const r = await this._db.execute(this._sql.getSql(), this._sql.getData());
|
|
826
719
|
if (r.packet === null) {
|
|
827
|
-
|
|
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');
|
|
720
|
+
lCore.log(this._ctr ?? {}, '[save, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
836
721
|
return false;
|
|
837
722
|
}
|
|
838
723
|
if (r.packet.affectedRows > 0) {
|
|
@@ -865,15 +750,7 @@ class Mod {
|
|
|
865
750
|
}
|
|
866
751
|
const r = await this._db.execute(this._sql.getSql(), this._sql.getData());
|
|
867
752
|
if (r.packet === null) {
|
|
868
|
-
|
|
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');
|
|
753
|
+
lCore.log(this._ctr ?? {}, '[remove, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
877
754
|
return false;
|
|
878
755
|
}
|
|
879
756
|
if (r.packet.affectedRows > 0) {
|
|
@@ -895,15 +772,7 @@ class Mod {
|
|
|
895
772
|
}
|
|
896
773
|
const r = await this._db.query(this._sql.getSql(), this._sql.getData());
|
|
897
774
|
if (r.rows === null) {
|
|
898
|
-
|
|
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');
|
|
775
|
+
lCore.log(this._ctr ?? {}, '[first, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
907
776
|
return false;
|
|
908
777
|
}
|
|
909
778
|
if (r.rows.length === 0) {
|
|
@@ -1034,15 +903,7 @@ class Mod {
|
|
|
1034
903
|
const lsql = sql.replace(/ LIMIT [0-9 ,]/g, ` LIMIT ${cz}, ${remain}`);
|
|
1035
904
|
const r = await this._db.query(lsql, this._sql.getData());
|
|
1036
905
|
if (r.rows === null) {
|
|
1037
|
-
|
|
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');
|
|
906
|
+
lCore.log(this._ctr ?? {}, '[all, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
1046
907
|
return false;
|
|
1047
908
|
}
|
|
1048
909
|
if (key) {
|
|
@@ -1075,18 +936,11 @@ class Mod {
|
|
|
1075
936
|
return Array.isArray(list) ? new Rows(list) : list;
|
|
1076
937
|
}
|
|
1077
938
|
// --- 单表 ---
|
|
939
|
+
/** --- 要追加的 values --- */
|
|
1078
940
|
const contain = this._contain ? lCore.clone(this._contain.list) : null;
|
|
1079
941
|
const r = await this._db.query(this._sql.getSql(), this._sql.getData());
|
|
1080
942
|
if (r.rows === null) {
|
|
1081
|
-
|
|
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');
|
|
943
|
+
lCore.log(this._ctr ?? {}, '[all, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
1090
944
|
return false;
|
|
1091
945
|
}
|
|
1092
946
|
// --- 检查没被查到的必包含项 ---
|
|
@@ -1102,7 +956,7 @@ class Mod {
|
|
|
1102
956
|
if (this._contain && contain?.length) {
|
|
1103
957
|
const csql = this._sql.copy(undefined, {
|
|
1104
958
|
'where': {
|
|
1105
|
-
[this._contain.key]:
|
|
959
|
+
[this._contain.key]: contain,
|
|
1106
960
|
}
|
|
1107
961
|
});
|
|
1108
962
|
cr = await this._db.query(csql.getSql(), csql.getData());
|
|
@@ -1211,15 +1065,7 @@ class Mod {
|
|
|
1211
1065
|
const lsql = sql.replace(/ LIMIT [0-9 ,]+/g, ` LIMIT ${cz}, ${remain}`);
|
|
1212
1066
|
const r = await this._db.query(lsql, this._sql.getData());
|
|
1213
1067
|
if (r.rows === null) {
|
|
1214
|
-
|
|
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');
|
|
1068
|
+
lCore.log(this._ctr ?? {}, '[allArray, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
1223
1069
|
return false;
|
|
1224
1070
|
}
|
|
1225
1071
|
if (key) {
|
|
@@ -1241,15 +1087,7 @@ class Mod {
|
|
|
1241
1087
|
const contain = this._contain ? lCore.clone(this._contain.list) : null;
|
|
1242
1088
|
const r = await this._db.query(this._sql.getSql(), this._sql.getData());
|
|
1243
1089
|
if (r.rows === null) {
|
|
1244
|
-
|
|
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');
|
|
1090
|
+
lCore.log(this._ctr ?? {}, '[allArray, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
1253
1091
|
return false;
|
|
1254
1092
|
}
|
|
1255
1093
|
// --- 检查没被查到的必包含项 ---
|
|
@@ -1265,7 +1103,7 @@ class Mod {
|
|
|
1265
1103
|
if (this._contain && contain?.length) {
|
|
1266
1104
|
const csql = this._sql.copy(undefined, {
|
|
1267
1105
|
'where': {
|
|
1268
|
-
[this._contain.key]:
|
|
1106
|
+
[this._contain.key]: contain,
|
|
1269
1107
|
}
|
|
1270
1108
|
});
|
|
1271
1109
|
cr = await this._db.query(csql.getSql(), csql.getData());
|
|
@@ -1298,15 +1136,7 @@ class Mod {
|
|
|
1298
1136
|
async explain(all = false) {
|
|
1299
1137
|
const r = await this._db.query('EXPLAIN ' + this._sql.getSql(), this._sql.getData());
|
|
1300
1138
|
if (r.rows === null) {
|
|
1301
|
-
|
|
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');
|
|
1139
|
+
lCore.log(this._ctr ?? {}, '[explain, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
1310
1140
|
return false;
|
|
1311
1141
|
}
|
|
1312
1142
|
if (!r.rows[0]) {
|
|
@@ -1341,15 +1171,7 @@ class Mod {
|
|
|
1341
1171
|
const sql = this._formatTotal(this._sql.getSql(), f);
|
|
1342
1172
|
const r = await this._db.query(sql, this._sql.getData());
|
|
1343
1173
|
if (r.rows === null) {
|
|
1344
|
-
|
|
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');
|
|
1174
|
+
lCore.log(this._ctr ?? {}, '[total, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
1353
1175
|
return 0;
|
|
1354
1176
|
}
|
|
1355
1177
|
let count = 0;
|
|
@@ -1365,15 +1187,7 @@ class Mod {
|
|
|
1365
1187
|
const sql = this._sql.getSql().replace(/SELECT .+? FROM/, 'SELECT COUNT(*) AS `count` FROM');
|
|
1366
1188
|
const r = await this._db.query(sql, this._sql.getData());
|
|
1367
1189
|
if (r.rows === null) {
|
|
1368
|
-
|
|
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');
|
|
1190
|
+
lCore.log(this._ctr ?? {}, '[count, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
1377
1191
|
return 0;
|
|
1378
1192
|
}
|
|
1379
1193
|
let count = 0;
|
|
@@ -1616,4 +1430,4 @@ Mod._$key = '';
|
|
|
1616
1430
|
Mod._$index = '';
|
|
1617
1431
|
/** ---- 可开启软删软更新软新增 --- */
|
|
1618
1432
|
Mod._$soft = false;
|
|
1619
|
-
|
|
1433
|
+
export default Mod;
|
package/sys/route.d.ts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
import * as http from 'http';
|
|
7
7
|
import * as http2 from 'http2';
|
|
8
8
|
import * as net from 'net';
|
|
9
|
-
import * as sCtr from './ctr';
|
|
10
|
-
import * as types from '
|
|
9
|
+
import * as sCtr from './ctr.js';
|
|
10
|
+
import * as types from '../types/index.js';
|
|
11
11
|
/**
|
|
12
12
|
* --- 清除已经加载的虚拟主机配置文件 ---
|
|
13
13
|
*/
|
package/sys/route.js
CHANGED
|
@@ -1,76 +1,35 @@
|
|
|
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.clearKebabConfigs = clearKebabConfigs;
|
|
37
|
-
exports.run = run;
|
|
38
|
-
exports.unlinkUploadFiles = unlinkUploadFiles;
|
|
39
|
-
exports.waitCtr = waitCtr;
|
|
40
|
-
exports.trimPost = trimPost;
|
|
41
|
-
exports.getFormData = getFormData;
|
|
42
1
|
/**
|
|
43
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
44
3
|
* Date: 2019-4-15 13:40
|
|
45
4
|
* Last: 2020-4-14 13:52:00, 2022-09-07 01:43:31, 2023-12-29 17:24:03, 2024-2-7 00:28:50, 2024-6-6 15:15:54, 2025-6-13 19:23:53
|
|
46
5
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
6
|
+
import * as http from 'http';
|
|
7
|
+
import * as stream from 'stream';
|
|
49
8
|
// --- 第三方 ---
|
|
50
|
-
|
|
9
|
+
import * as ws from '@litert/websocket';
|
|
51
10
|
// --- 库和定义 ---
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
11
|
+
import * as lFs from '../lib/fs.js';
|
|
12
|
+
import * as lZlib from '../lib/zlib.js';
|
|
13
|
+
import * as lCore from '../lib/core.js';
|
|
14
|
+
import * as lText from '../lib/text.js';
|
|
15
|
+
import * as lTime from '../lib/time.js';
|
|
16
|
+
import * as lResponse from '../lib/net/response.js';
|
|
17
|
+
import * as lWs from '../lib/ws.js';
|
|
18
|
+
import * as sCtr from './ctr.js';
|
|
19
|
+
import * as kebab from '../index.js';
|
|
61
20
|
/** --- 动态层 kebab.json 缓存(文件路径: 最终合并值) --- */
|
|
62
21
|
let kebabConfigs = {};
|
|
63
22
|
/**
|
|
64
23
|
* --- 清除已经加载的虚拟主机配置文件 ---
|
|
65
24
|
*/
|
|
66
|
-
function clearKebabConfigs() {
|
|
25
|
+
export function clearKebabConfigs() {
|
|
67
26
|
kebabConfigs = {};
|
|
68
27
|
}
|
|
69
28
|
/**
|
|
70
29
|
* --- 若为动态路径则执行此函数,此函数不进行判断 kebab.json 是否存在 ---
|
|
71
30
|
* @param data 传导的数据
|
|
72
31
|
*/
|
|
73
|
-
async function run(data) {
|
|
32
|
+
export async function run(data) {
|
|
74
33
|
// --- 检测 path 是否是静态文件 ---
|
|
75
34
|
if (/^(stc\/.*|favicon.\w+?\??.*|apple[\w-]+?\.png\??.*|[\w-]+?\.txt\??.*|[\w-]+?\.html\??.*)/.test(data.path)) {
|
|
76
35
|
return false;
|
|
@@ -129,8 +88,9 @@ async function run(data) {
|
|
|
129
88
|
'startTime': process.hrtime.bigint(),
|
|
130
89
|
'startMemory': process.memoryUsage().rss,
|
|
131
90
|
// --- 环境判断 ---
|
|
132
|
-
'mobile': data.req.headers['user-agent'] ? data.req.headers['user-agent'].includes('mobile') : false,
|
|
133
|
-
'wechat': data.req.headers['user-agent'] ? data.req.headers['user-agent'].includes('micromessenger') : false,
|
|
91
|
+
'mobile': data.req.headers['user-agent'] ? data.req.headers['user-agent'].toLowerCase().includes('mobile') : false,
|
|
92
|
+
'wechat': data.req.headers['user-agent'] ? data.req.headers['user-agent'].toLowerCase().includes('micromessenger') : false,
|
|
93
|
+
'miniprogram': data.req.headers['referer'] ? (data.req.headers['referer'].toLowerCase().startsWith('https://servicewechat.com/') ? 'wechat' : '') : '',
|
|
134
94
|
'https': data.uri.protocol === 'https' ? true : false,
|
|
135
95
|
'host': data.uri.host ?? '',
|
|
136
96
|
'hostname': data.uri.hostname ?? '',
|
|
@@ -293,12 +253,14 @@ async function run(data) {
|
|
|
293
253
|
return true;
|
|
294
254
|
}
|
|
295
255
|
// --- 加载控制器文件 ---
|
|
296
|
-
const ctrCtr = (await
|
|
256
|
+
const ctrCtr = (await import((!filePath.startsWith('/') ? '/' : '') + filePath)).default;
|
|
297
257
|
const cctr = new ctrCtr(config, data.req);
|
|
298
258
|
// --- 先处理 web socket 的情况 ---
|
|
299
259
|
let wsSocket;
|
|
300
260
|
try {
|
|
301
261
|
const options = await cctr.onUpgrade();
|
|
262
|
+
// --- 默认无消息发送 3 分钟 ---
|
|
263
|
+
options.timeout ??= 60_000 * 3;
|
|
302
264
|
wsSocket = lWs.createServer(data.req, data.socket, options);
|
|
303
265
|
cctr.setPrototype('_socket', wsSocket);
|
|
304
266
|
}
|
|
@@ -412,7 +374,7 @@ async function run(data) {
|
|
|
412
374
|
return true;
|
|
413
375
|
}
|
|
414
376
|
// --- 加载中间控制器 ---
|
|
415
|
-
const middleCtr = (await
|
|
377
|
+
const middleCtr = (await import((!config.const.ctrPath.startsWith('/') ? '/' : '') + config.const.ctrPath + 'middle.js')).default;
|
|
416
378
|
const middle = new middleCtr(config, data.req, data.res);
|
|
417
379
|
/** --- 可能存在的最终控制器 --- */
|
|
418
380
|
let cctr = null;
|
|
@@ -472,7 +434,7 @@ async function run(data) {
|
|
|
472
434
|
return true;
|
|
473
435
|
}
|
|
474
436
|
// --- 加载控制器文件 ---
|
|
475
|
-
const ctrCtr = (await
|
|
437
|
+
const ctrCtr = (await import((!filePath.startsWith('/') ? '/' : '') + filePath)).default;
|
|
476
438
|
cctr = new ctrCtr(config, data.req, data.res ?? data.socket);
|
|
477
439
|
// --- 对信息进行初始化 ---
|
|
478
440
|
cctr.setPrototype('_timer', middle.getPrototype('_timer'));
|
|
@@ -792,7 +754,7 @@ function getWsCtrName(path) {
|
|
|
792
754
|
* --- 删除本次请求所有已上传的临时文件, Mutton: false, Kebab: true ---
|
|
793
755
|
* @param cctr Ctr 对象 或 files
|
|
794
756
|
*/
|
|
795
|
-
async function unlinkUploadFiles(cctr) {
|
|
757
|
+
export async function unlinkUploadFiles(cctr) {
|
|
796
758
|
const cfiles = cctr instanceof sCtr.Ctr ? cctr.getPrototype('_files') : cctr;
|
|
797
759
|
for (const name in cfiles) {
|
|
798
760
|
let files = cfiles[name];
|
|
@@ -809,7 +771,7 @@ async function unlinkUploadFiles(cctr) {
|
|
|
809
771
|
* --- 此时其实已经给客户端返回了,此处等待不消耗客户端的等待时间 ---
|
|
810
772
|
* @param cctr 要等待的控制器 ---
|
|
811
773
|
*/
|
|
812
|
-
async function waitCtr(cctr) {
|
|
774
|
+
export async function waitCtr(cctr) {
|
|
813
775
|
// --- 先判断异步任务是否结束 ---
|
|
814
776
|
const waitInfo = cctr.getPrototype('_waitInfo');
|
|
815
777
|
if (waitInfo.asyncTask.count) {
|
|
@@ -829,7 +791,7 @@ async function waitCtr(cctr) {
|
|
|
829
791
|
* --- 将 POST 数据的值执行 trim ---
|
|
830
792
|
* @param post
|
|
831
793
|
*/
|
|
832
|
-
function trimPost(post) {
|
|
794
|
+
export function trimPost(post) {
|
|
833
795
|
for (const key in post) {
|
|
834
796
|
const val = post[key];
|
|
835
797
|
if (typeof val === 'string') {
|
|
@@ -881,7 +843,7 @@ function getPost(req) {
|
|
|
881
843
|
* @param req 请求头
|
|
882
844
|
* @param events 文件处理情况
|
|
883
845
|
*/
|
|
884
|
-
function getFormData(req, events = {}) {
|
|
846
|
+
export function getFormData(req, events = {}) {
|
|
885
847
|
return new Promise(function (resolve) {
|
|
886
848
|
const ct = req.headers['content-type'] ?? '';
|
|
887
849
|
if (!ct) {
|
package/types/index.d.ts
CHANGED
package/www/example/ctr/main.js
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 ctr = __importStar(require("~/sys/ctr"));
|
|
37
|
-
class default_1 extends ctr.Ctr {
|
|
1
|
+
import * as ctr from '../../../sys/ctr.js';
|
|
2
|
+
export default class extends ctr.Ctr {
|
|
38
3
|
index() {
|
|
39
4
|
return `<a href="${this._config.const.urlBase}test">Hello world! Click here to visit demo.</a>`;
|
|
40
5
|
}
|
|
41
6
|
}
|
|
42
|
-
exports.default = default_1;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as ctr from '
|
|
2
|
-
import * as types from '
|
|
1
|
+
import * as ctr from '../../../sys/ctr.js';
|
|
2
|
+
import * as types from '../../../types/index.js';
|
|
3
3
|
export default class extends ctr.Ctr {
|
|
4
4
|
onLoad(): string | boolean;
|
|
5
5
|
onUnload(rtn: string | boolean | types.DbValue[]): string | boolean | types.DbValue[];
|