@maiyunnet/kebab 2.0.16 → 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 +4 -11
- 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 +20 -59
- 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 +2 -2
- package/lib/ws.js +14 -56
- package/lib/zip.d.ts +1 -1
- package/lib/zip.js +6 -47
- package/lib/zlib.js +17 -68
- 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 +9 -47
- package/sys/master.js +11 -46
- package/sys/mod.d.ts +9 -5
- package/sys/mod.js +9 -43
- package/sys/route.d.ts +2 -2
- package/sys/route.js +24 -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 +1 -1
- package/www/example/ws/rsocket.js +5 -40
- package/www/example/ws/test.d.ts +1 -1
- package/www/example/ws/test.js +7 -42
- package/eslint.config.js +0 -22
package/lib/net.js
CHANGED
|
@@ -1,74 +1,25 @@
|
|
|
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.getCa = getCa;
|
|
37
|
-
exports.open = open;
|
|
38
|
-
exports.get = get;
|
|
39
|
-
exports.post = post;
|
|
40
|
-
exports.postJson = postJson;
|
|
41
|
-
exports.request = request;
|
|
42
|
-
exports.setCookie = setCookie;
|
|
43
|
-
exports.buildCookieQuery = buildCookieQuery;
|
|
44
|
-
exports.resetCookieSession = resetCookieSession;
|
|
45
|
-
exports.getFormData = getFormData;
|
|
46
|
-
exports.filterProxyHeaders = filterProxyHeaders;
|
|
47
|
-
exports.mproxy = mproxy;
|
|
48
|
-
exports.mproxyData = mproxyData;
|
|
49
|
-
exports.rproxy = rproxy;
|
|
50
1
|
/**
|
|
51
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
52
3
|
* Date: 2019-5-15 22:47
|
|
53
4
|
* CA: https://curl.haxx.se/ca/cacert.pem
|
|
54
5
|
* Last: 2020-4-9 20:11:02, 2022-09-22 14:30:13, 2024-1-1 21:32:26, 2024-1-12 13:01:54, 2025-6-13 13:20:52
|
|
55
6
|
*/
|
|
56
|
-
|
|
7
|
+
import * as stream from 'stream';
|
|
57
8
|
// --- 第三方 ---
|
|
58
|
-
|
|
9
|
+
import * as hc from '@litert/http-client';
|
|
59
10
|
// --- 库和定义 ---
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
11
|
+
import * as fs from '../lib/fs.js';
|
|
12
|
+
import * as text from '../lib/text.js';
|
|
13
|
+
import * as time from '../lib/time.js';
|
|
14
|
+
import * as kebab from '../index.js';
|
|
64
15
|
// --- 自己 ---
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
16
|
+
import * as fd from './net/formdata.js';
|
|
17
|
+
import * as lRequest from './net/request.js';
|
|
18
|
+
import * as response from './net/response.js';
|
|
68
19
|
/** --- ca 根证书内容 --- */
|
|
69
20
|
let ca = '';
|
|
70
21
|
/** --- 获取 CA 证书 --- */
|
|
71
|
-
async function getCa() {
|
|
22
|
+
export async function getCa() {
|
|
72
23
|
if (ca) {
|
|
73
24
|
return ca;
|
|
74
25
|
}
|
|
@@ -83,7 +34,7 @@ const reuses = {
|
|
|
83
34
|
* --- 创建一个请求对象 ---
|
|
84
35
|
* @param u
|
|
85
36
|
*/
|
|
86
|
-
function open(u) {
|
|
37
|
+
export function open(u) {
|
|
87
38
|
return new lRequest.Request(u);
|
|
88
39
|
}
|
|
89
40
|
/**
|
|
@@ -91,7 +42,7 @@ function open(u) {
|
|
|
91
42
|
* @param u 请求的 URL
|
|
92
43
|
* @param opt 参数
|
|
93
44
|
*/
|
|
94
|
-
async function get(u, opt = {}) {
|
|
45
|
+
export async function get(u, opt = {}) {
|
|
95
46
|
return request(u, undefined, opt);
|
|
96
47
|
}
|
|
97
48
|
/**
|
|
@@ -100,7 +51,7 @@ async function get(u, opt = {}) {
|
|
|
100
51
|
* @param data 要发送的数据
|
|
101
52
|
* @param opt 参数
|
|
102
53
|
*/
|
|
103
|
-
async function post(u, data, opt = {}) {
|
|
54
|
+
export async function post(u, data, opt = {}) {
|
|
104
55
|
opt.method = 'POST';
|
|
105
56
|
return request(u, data, opt);
|
|
106
57
|
}
|
|
@@ -110,7 +61,7 @@ async function post(u, data, opt = {}) {
|
|
|
110
61
|
* @param data
|
|
111
62
|
* @param opt
|
|
112
63
|
*/
|
|
113
|
-
async function postJson(u, data, opt = {}) {
|
|
64
|
+
export async function postJson(u, data, opt = {}) {
|
|
114
65
|
opt.method = 'POST';
|
|
115
66
|
opt.type = 'json';
|
|
116
67
|
return request(u, data, opt);
|
|
@@ -119,7 +70,7 @@ async function postJson(u, data, opt = {}) {
|
|
|
119
70
|
* --- 发起一个请求 ---
|
|
120
71
|
* @param opt 配置项
|
|
121
72
|
*/
|
|
122
|
-
async function request(u, data, opt = {}) {
|
|
73
|
+
export async function request(u, data, opt = {}) {
|
|
123
74
|
const uri = text.parseUrl(u);
|
|
124
75
|
/** --- 正向代理的地址 --- */
|
|
125
76
|
const puri = opt.mproxy ? text.parseUrl(opt.mproxy.url) : null;
|
|
@@ -209,7 +160,7 @@ async function request(u, data, opt = {}) {
|
|
|
209
160
|
'localAddress': local,
|
|
210
161
|
'ca': ca,
|
|
211
162
|
'connectionOptions': {
|
|
212
|
-
'remoteHost': hosts[host]
|
|
163
|
+
'remoteHost': hosts[host],
|
|
213
164
|
},
|
|
214
165
|
});
|
|
215
166
|
}
|
|
@@ -289,7 +240,7 @@ async function request(u, data, opt = {}) {
|
|
|
289
240
|
* @param domain 应用网址,如 .xxx.com
|
|
290
241
|
* @param opt 选项 ttl, path, ssl, httponly
|
|
291
242
|
*/
|
|
292
|
-
function setCookie(cookie, name, value, domain, opt = {}) {
|
|
243
|
+
export function setCookie(cookie, name, value, domain, opt = {}) {
|
|
293
244
|
const tim = time.stamp();
|
|
294
245
|
const ttl = opt.ttl ?? 0;
|
|
295
246
|
domain = domain.split(':')[0];
|
|
@@ -414,7 +365,7 @@ async function buildCookieObject(cookie, setCookies, uri) {
|
|
|
414
365
|
* @param cookie cookie 对象
|
|
415
366
|
* @param uri 请求的 URI 对象
|
|
416
367
|
*/
|
|
417
|
-
function buildCookieQuery(cookie, uri) {
|
|
368
|
+
export function buildCookieQuery(cookie, uri) {
|
|
418
369
|
const tim = time.stamp();
|
|
419
370
|
let cookieStr = '';
|
|
420
371
|
for (const key in cookie) {
|
|
@@ -463,7 +414,7 @@ function buildCookieQuery(cookie, uri) {
|
|
|
463
414
|
* --- 模拟重启浏览器后的状态 ---
|
|
464
415
|
* @param cookie cookie 对象
|
|
465
416
|
*/
|
|
466
|
-
function resetCookieSession(cookie) {
|
|
417
|
+
export function resetCookieSession(cookie) {
|
|
467
418
|
for (const key in cookie) {
|
|
468
419
|
const item = cookie[key];
|
|
469
420
|
if (item.exp === -1992199400000) {
|
|
@@ -474,7 +425,7 @@ function resetCookieSession(cookie) {
|
|
|
474
425
|
/**
|
|
475
426
|
* --- 创建 FormData 对象, Mutton: false, Kebab: true ---
|
|
476
427
|
*/
|
|
477
|
-
function getFormData() {
|
|
428
|
+
export function getFormData() {
|
|
478
429
|
return new fd.FormData();
|
|
479
430
|
}
|
|
480
431
|
/** --- proxy 要剔除的基础头部 --- */
|
|
@@ -484,7 +435,7 @@ const proxyContinueHeaders = ['host', 'connection', 'http-version', 'http-code',
|
|
|
484
435
|
* @param headers 剔除前的 header
|
|
485
436
|
* @param res 直接设置头部而不返回,可置空
|
|
486
437
|
*/
|
|
487
|
-
function filterProxyHeaders(headers, res) {
|
|
438
|
+
export function filterProxyHeaders(headers, res) {
|
|
488
439
|
const heads = {};
|
|
489
440
|
for (const h in headers) {
|
|
490
441
|
if (proxyContinueHeaders.includes(h)) {
|
|
@@ -512,7 +463,7 @@ function filterProxyHeaders(headers, res) {
|
|
|
512
463
|
* @param auth 校验字符串,读取 get 的 auth 和本参数做比对
|
|
513
464
|
* @param opt 参数
|
|
514
465
|
*/
|
|
515
|
-
async function mproxy(ctr, auth, opt = {}) {
|
|
466
|
+
export async function mproxy(ctr, auth, opt = {}) {
|
|
516
467
|
const req = ctr.getPrototype('_req');
|
|
517
468
|
const res = ctr.getPrototype('_res');
|
|
518
469
|
const input = ctr.getPrototype('_input');
|
|
@@ -547,7 +498,7 @@ async function mproxy(ctr, auth, opt = {}) {
|
|
|
547
498
|
* --- 获取 mproxy 的附加数据 ---
|
|
548
499
|
* @param ctr 当前控制器
|
|
549
500
|
*/
|
|
550
|
-
function mproxyData(ctr) {
|
|
501
|
+
export function mproxyData(ctr) {
|
|
551
502
|
const get = ctr.getPrototype('_get');
|
|
552
503
|
if (!get['data']) {
|
|
553
504
|
return {};
|
|
@@ -564,7 +515,7 @@ function mproxyData(ctr) {
|
|
|
564
515
|
* @param route 要反代的路由
|
|
565
516
|
* @param opt 参数
|
|
566
517
|
*/
|
|
567
|
-
async function rproxy(ctr, route, opt = {}) {
|
|
518
|
+
export async function rproxy(ctr, route, opt = {}) {
|
|
568
519
|
const req = ctr.getPrototype('_req');
|
|
569
520
|
const res = ctr.getPrototype('_res');
|
|
570
521
|
const config = ctr.getPrototype('_config');
|
package/lib/s3.d.ts
CHANGED
package/lib/s3.js
CHANGED
|
@@ -1,85 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Project: Kebab, User: Tang Rukun, JianSuoQiYue
|
|
4
3
|
* Date: 2024-2-18 18:32:45
|
|
5
4
|
* Last: 2024-2-18 18:32:47, 2024-3-16 16:42:27, 2024-5-31 21:36:26, 2024-7-8 00:28:42, 2024-7-19 11:32:43, 2025-6-10 21:45:34
|
|
6
5
|
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.S3 = exports.ESERVICE = void 0;
|
|
42
|
-
exports.get = get;
|
|
43
6
|
// --- 库和定义 ---
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
7
|
+
import * as s3 from '@aws-sdk/client-s3';
|
|
8
|
+
import * as ls from '@aws-sdk/lib-storage';
|
|
9
|
+
import * as lCore from '../lib/core.js';
|
|
10
|
+
import * as lText from '../lib/text.js';
|
|
48
11
|
/**
|
|
49
12
|
* s3 文档:https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/
|
|
50
13
|
*/
|
|
51
14
|
/** --- 服务商定义 --- */
|
|
52
|
-
var ESERVICE;
|
|
15
|
+
export var ESERVICE;
|
|
53
16
|
(function (ESERVICE) {
|
|
54
17
|
ESERVICE[ESERVICE["AMAZON"] = 0] = "AMAZON";
|
|
55
18
|
ESERVICE[ESERVICE["TENCENT"] = 1] = "TENCENT";
|
|
56
19
|
ESERVICE[ESERVICE["ALIBABA"] = 2] = "ALIBABA";
|
|
57
20
|
ESERVICE[ESERVICE["CF"] = 3] = "CF";
|
|
58
|
-
})(ESERVICE || (
|
|
59
|
-
class S3 {
|
|
21
|
+
})(ESERVICE || (ESERVICE = {}));
|
|
22
|
+
export class S3 {
|
|
60
23
|
constructor(ctr, opt) {
|
|
61
24
|
/** --- bucket 名 --- */
|
|
62
25
|
this._bucket = '';
|
|
63
26
|
this._ctr = ctr;
|
|
64
27
|
const config = ctr.getPrototype('_config');
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this._bucket = opt.bucket;
|
|
28
|
+
const account = config.s3?.[ESERVICE[opt.service]]?.account ?? '';
|
|
29
|
+
const secretId = config.s3?.[ESERVICE[opt.service]]?.sid ?? '';
|
|
30
|
+
const secretKey = config.s3?.[ESERVICE[opt.service]]?.skey ?? '';
|
|
31
|
+
const region = config.s3?.[ESERVICE[opt.service]]?.region ?? '';
|
|
32
|
+
this._bucket = config.s3?.[ESERVICE[opt.service]]?.bucket ?? '';
|
|
71
33
|
let endpoint;
|
|
72
34
|
switch (opt.service) {
|
|
73
35
|
case ESERVICE.TENCENT: {
|
|
74
|
-
endpoint = `https://cos.${
|
|
36
|
+
endpoint = `https://cos.${region}.myqcloud.com`;
|
|
75
37
|
break;
|
|
76
38
|
}
|
|
77
39
|
case ESERVICE.ALIBABA: {
|
|
78
|
-
endpoint = `https://oss-${
|
|
40
|
+
endpoint = `https://oss-${region}.aliyuncs.com`;
|
|
79
41
|
break;
|
|
80
42
|
}
|
|
81
43
|
case ESERVICE.CF: {
|
|
82
|
-
endpoint = `https://${
|
|
44
|
+
endpoint = `https://${account}.r2.cloudflarestorage.com`;
|
|
83
45
|
break;
|
|
84
46
|
}
|
|
85
47
|
default: {
|
|
@@ -87,12 +49,12 @@ class S3 {
|
|
|
87
49
|
}
|
|
88
50
|
}
|
|
89
51
|
this._link = new s3.S3Client({
|
|
90
|
-
'region':
|
|
52
|
+
'region': region,
|
|
91
53
|
'credentials': {
|
|
92
|
-
'accessKeyId':
|
|
93
|
-
'secretAccessKey':
|
|
54
|
+
'accessKeyId': secretId,
|
|
55
|
+
'secretAccessKey': secretKey,
|
|
94
56
|
},
|
|
95
|
-
'endpoint': endpoint
|
|
57
|
+
'endpoint': endpoint,
|
|
96
58
|
});
|
|
97
59
|
}
|
|
98
60
|
/**
|
|
@@ -221,11 +183,10 @@ class S3 {
|
|
|
221
183
|
}
|
|
222
184
|
}
|
|
223
185
|
}
|
|
224
|
-
exports.S3 = S3;
|
|
225
186
|
/**
|
|
226
187
|
* --- 创建一个对象存储对象 ---
|
|
227
188
|
* @param opt 选项
|
|
228
189
|
*/
|
|
229
|
-
function get(ctr, opt) {
|
|
190
|
+
export function get(ctr, opt) {
|
|
230
191
|
return new S3(ctr, opt);
|
|
231
192
|
}
|
package/lib/scan.d.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Date: 2022-09-24 15:23:25
|
|
4
4
|
* Last: 2022-09-24 15:23:25, 2022-9-26 12:37:01, 2022-12-29 00:11:16
|
|
5
5
|
*/
|
|
6
|
-
import * as lDb from '
|
|
7
|
-
import * as lKv from '
|
|
8
|
-
import * as sCtr from '
|
|
6
|
+
import * as lDb from '../lib/db.js';
|
|
7
|
+
import * as lKv from '../lib/kv.js';
|
|
8
|
+
import * as sCtr from '../sys/ctr.js';
|
|
9
9
|
/** --- Scan 设置的选项 --- */
|
|
10
10
|
export interface IOptions {
|
|
11
11
|
'ttl'?: number;
|
package/lib/scan.js
CHANGED
|
@@ -1,47 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
4
3
|
* Date: 2022-09-24 15:23:25
|
|
5
4
|
* Last: 2022-09-24 15:23:25, 2022-9-26 12:37:01, 2022-12-29 00:11:16
|
|
6
5
|
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.Scan = void 0;
|
|
42
|
-
exports.get = get;
|
|
43
|
-
exports.scanned = scanned;
|
|
44
|
-
exports.setData = setData;
|
|
45
6
|
/*
|
|
46
7
|
CREATE TABLE IF NOT EXISTS `scan` (
|
|
47
8
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
@@ -56,13 +17,13 @@ CREATE TABLE IF NOT EXISTS `scan` (
|
|
|
56
17
|
KEY `time_exp` (`time_exp`)
|
|
57
18
|
) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
|
58
19
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class Scan {
|
|
20
|
+
import * as lCore from '../lib/core.js';
|
|
21
|
+
import * as lDb from '../lib/db.js';
|
|
22
|
+
import * as lKv from '../lib/kv.js';
|
|
23
|
+
import * as lSql from '../lib/sql.js';
|
|
24
|
+
import * as lTime from '../lib/time.js';
|
|
25
|
+
import * as lText from '../lib/text.js';
|
|
26
|
+
export class Scan {
|
|
66
27
|
constructor(link, token, opt = {}) {
|
|
67
28
|
this._sql = null;
|
|
68
29
|
/** --- 表名或者 kv 里 key 的前缀 --- */
|
|
@@ -242,14 +203,13 @@ class Scan {
|
|
|
242
203
|
await this._link.execute(this._sql.getSql(), this._sql.getData());
|
|
243
204
|
}
|
|
244
205
|
}
|
|
245
|
-
exports.Scan = Scan;
|
|
246
206
|
/**
|
|
247
207
|
* -- 创建 Scan 对象 ---
|
|
248
208
|
* @param link
|
|
249
209
|
* @param token Token
|
|
250
210
|
* @param opt
|
|
251
211
|
*/
|
|
252
|
-
async function get(link, token, opt = {}) {
|
|
212
|
+
export async function get(link, token, opt = {}) {
|
|
253
213
|
const scan = new Scan(link, token, opt);
|
|
254
214
|
if (!token) {
|
|
255
215
|
await scan.createToken();
|
|
@@ -262,7 +222,7 @@ async function get(link, token, opt = {}) {
|
|
|
262
222
|
* @patam token 必填
|
|
263
223
|
* @param opt
|
|
264
224
|
*/
|
|
265
|
-
async function scanned(link, token, opt = {}) {
|
|
225
|
+
export async function scanned(link, token, opt = {}) {
|
|
266
226
|
const time = lTime.stamp();
|
|
267
227
|
const name = opt.name ?? 'scan';
|
|
268
228
|
if (link instanceof lDb.Pool) {
|
|
@@ -311,7 +271,7 @@ async function scanned(link, token, opt = {}) {
|
|
|
311
271
|
* @param data
|
|
312
272
|
* @param opt
|
|
313
273
|
*/
|
|
314
|
-
async function setData(link, token, data, opt = {}) {
|
|
274
|
+
export async function setData(link, token, data, opt = {}) {
|
|
315
275
|
if (typeof data === 'number' && Number.isInteger(data)) {
|
|
316
276
|
if (data >= -3 && data <= 1) {
|
|
317
277
|
return false;
|
package/lib/session.d.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Date: 2019-6-5 22:01:40
|
|
4
4
|
* Last: 2020-3-30 00:11:15, 2022-12-29 00:10:28, 2023-5-24 18:59:27
|
|
5
5
|
*/
|
|
6
|
-
import * as db from '
|
|
7
|
-
import * as kv from '
|
|
8
|
-
import * as ctr from '
|
|
6
|
+
import * as db from '../lib/db.js';
|
|
7
|
+
import * as kv from '../lib/kv.js';
|
|
8
|
+
import * as ctr from '../sys/ctr.js';
|
|
9
9
|
export interface IOptions {
|
|
10
10
|
'name'?: string;
|
|
11
11
|
'ttl'?: number;
|
package/lib/session.js
CHANGED
|
@@ -1,44 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
4
3
|
* Date: 2019-6-5 22:01:40
|
|
5
4
|
* Last: 2020-3-30 00:11:15, 2022-12-29 00:10:28, 2023-5-24 18:59:27
|
|
6
5
|
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.Session = void 0;
|
|
42
6
|
/*
|
|
43
7
|
* --- Mysql ---
|
|
44
8
|
CREATE TABLE `session` (
|
|
@@ -53,13 +17,13 @@ CREATE TABLE `session` (
|
|
|
53
17
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
|
54
18
|
*/
|
|
55
19
|
// --- 库和定义 ---
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
class Session {
|
|
20
|
+
import * as core from '../lib/core.js';
|
|
21
|
+
import * as time from '../lib/time.js';
|
|
22
|
+
import * as db from '../lib/db.js';
|
|
23
|
+
import * as kv from '../lib/kv.js';
|
|
24
|
+
import * as sql from '../lib/sql.js';
|
|
25
|
+
import * as text from '../lib/text.js';
|
|
26
|
+
export class Session {
|
|
63
27
|
constructor() {
|
|
64
28
|
/** --- 当前 Session 的 token --- */
|
|
65
29
|
this._token = '';
|
|
@@ -75,10 +39,10 @@ class Session {
|
|
|
75
39
|
*/
|
|
76
40
|
async init(ctr, link, auth = false, opt = {}) {
|
|
77
41
|
const config = ctr.getPrototype('_config');
|
|
78
|
-
const ssl = opt.ssl ?? config.session.ssl;
|
|
42
|
+
const ssl = opt.ssl ?? config.session.ssl ?? false;
|
|
79
43
|
const pre = opt.sqlPre ?? null;
|
|
80
44
|
this._name = opt.name ?? config.session.name;
|
|
81
|
-
this._ttl = opt.ttl ?? config.session.ttl;
|
|
45
|
+
this._ttl = opt.ttl ?? config.session.ttl ?? 172800;
|
|
82
46
|
const tim = time.stamp();
|
|
83
47
|
this._ctr = ctr;
|
|
84
48
|
if (auth) {
|
|
@@ -225,4 +189,3 @@ class Session {
|
|
|
225
189
|
await this._link.execute(this._sql.getSql(), this._sql.getData());
|
|
226
190
|
}
|
|
227
191
|
}
|
|
228
|
-
exports.Session = Session;
|
package/lib/sql.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Date: 2019-5-27 20:18:50
|
|
4
4
|
* Last: 2020-3-29 19:37:25, 2022-07-24 22:38:11, 2023-5-24 18:49:18, 2023-6-13 22:20:21, 2023-12-11 13:58:54, 2023-12-14 13:14:40, 2023-12-21 00:04:40, 2024-4-11 19:29:29, 2024-9-2 17:15:28, 2025-8-3 21:28:18
|
|
5
5
|
*/
|
|
6
|
-
import * as ctr from '
|
|
7
|
-
import * as types from '
|
|
6
|
+
import * as ctr from '../sys/ctr.js';
|
|
7
|
+
import * as types from '../types/index.js';
|
|
8
8
|
export declare class Sql {
|
|
9
9
|
/** --- 前置 --- */
|
|
10
10
|
private readonly _pre;
|
package/lib/sql.js
CHANGED
|
@@ -1,57 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
4
3
|
* Date: 2019-5-27 20:18:50
|
|
5
4
|
* Last: 2020-3-29 19:37:25, 2022-07-24 22:38:11, 2023-5-24 18:49:18, 2023-6-13 22:20:21, 2023-12-11 13:58:54, 2023-12-14 13:14:40, 2023-12-21 00:04:40, 2024-4-11 19:29:29, 2024-9-2 17:15:28, 2025-8-3 21:28:18
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.Sql = void 0;
|
|
42
|
-
exports.get = get;
|
|
43
|
-
exports.format = format;
|
|
44
|
-
exports.aoMix = aoMix;
|
|
45
|
-
exports.column = column;
|
|
46
|
-
const lText = __importStar(require("~/lib/text"));
|
|
47
|
-
const lCore = __importStar(require("~/lib/core"));
|
|
6
|
+
import * as lText from '../lib/text.js';
|
|
7
|
+
import * as lCore from '../lib/core.js';
|
|
48
8
|
// --- 第三方 ---
|
|
49
|
-
|
|
9
|
+
import * as mysql2 from 'mysql2/promise';
|
|
50
10
|
// --- 库和定义 ---
|
|
51
|
-
|
|
11
|
+
import * as ctr from '../sys/ctr.js';
|
|
52
12
|
/** --- filed 用 token --- */
|
|
53
13
|
let columnToken = '';
|
|
54
|
-
class Sql {
|
|
14
|
+
export class Sql {
|
|
55
15
|
// --- 实例化 ---
|
|
56
16
|
constructor(pre, opt = {}) {
|
|
57
17
|
/** --- 前置 --- */
|
|
@@ -1018,13 +978,12 @@ class Sql {
|
|
|
1018
978
|
return true;
|
|
1019
979
|
}
|
|
1020
980
|
}
|
|
1021
|
-
exports.Sql = Sql;
|
|
1022
981
|
/**
|
|
1023
982
|
* --- 创建 sql 对象 ---
|
|
1024
983
|
* @param ctrPre ctr 对象或 pre 表前缀
|
|
1025
984
|
* @param opt 参数
|
|
1026
985
|
*/
|
|
1027
|
-
function get(ctrPre, opt = {}) {
|
|
986
|
+
export function get(ctrPre, opt = {}) {
|
|
1028
987
|
return new Sql(ctrPre instanceof ctr.Ctr ? ctrPre.getPrototype('_config').sql.pre : ctrPre, opt);
|
|
1029
988
|
}
|
|
1030
989
|
/**
|
|
@@ -1032,14 +991,14 @@ function get(ctrPre, opt = {}) {
|
|
|
1032
991
|
* @param sql SQL 字符串
|
|
1033
992
|
* @param data DATA 数据
|
|
1034
993
|
*/
|
|
1035
|
-
function format(sql, data) {
|
|
994
|
+
export function format(sql, data) {
|
|
1036
995
|
return mysql2.format(sql, data);
|
|
1037
996
|
}
|
|
1038
997
|
/**
|
|
1039
998
|
* --- 将数组兑换为组合的对象(Array/Object mix) ---
|
|
1040
999
|
* @param arr 要转换的数组
|
|
1041
1000
|
*/
|
|
1042
|
-
function aoMix(arr) {
|
|
1001
|
+
export function aoMix(arr) {
|
|
1043
1002
|
if (!Array.isArray(arr)) {
|
|
1044
1003
|
return arr;
|
|
1045
1004
|
}
|
|
@@ -1059,7 +1018,7 @@ function aoMix(arr) {
|
|
|
1059
1018
|
return mix;
|
|
1060
1019
|
}
|
|
1061
1020
|
/** --- 创建字段对象 --- */
|
|
1062
|
-
function column(field) {
|
|
1021
|
+
export function column(field) {
|
|
1063
1022
|
if (!columnToken) {
|
|
1064
1023
|
columnToken = lCore.random(8, lCore.RANDOM_LUNS);
|
|
1065
1024
|
}
|