@maiyunnet/kebab 3.1.7 → 3.1.8
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 +1 -1
- package/index.js +2 -2
- package/lib/core.d.ts +1 -1
- package/lib/core.js +1 -2
- package/lib/net.d.ts +3 -3
- package/lib/net.js +5 -7
- package/lib/text.d.ts +7 -3
- package/lib/text.js +22 -4
- package/package.json +1 -1
- package/sys/ctr.d.ts +2 -0
- package/sys/ctr.js +4 -2
- package/sys/mod.d.ts +2 -2
- package/sys/mod.js +2 -2
- package/sys/route.d.ts +8 -4
- package/sys/route.js +43 -36
- package/www/example/ctr/middle.d.ts +1 -0
- package/www/example/ctr/middle.js +9 -0
- package/www/example/ctr/test.js +2 -2
- package/tsconfig.json +0 -26
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* ------------------------
|
|
10
10
|
*/
|
|
11
11
|
/** --- 当前系统版本号 --- */
|
|
12
|
-
export const VER = '3.1.
|
|
12
|
+
export const VER = '3.1.8';
|
|
13
13
|
// --- 服务端用的路径 ---
|
|
14
|
-
const imu = import.meta.url.replace('file://', '').replace(/^\/(\w:)/, '$1')
|
|
14
|
+
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
15
15
|
/** --- /xxx/xxx --- */
|
|
16
16
|
const dirname = imu.slice(0, imu.lastIndexOf('/'));
|
|
17
17
|
/** --- 框架根目录,以 / 结尾 --- */
|
package/lib/core.d.ts
CHANGED
package/lib/core.js
CHANGED
|
@@ -304,7 +304,6 @@ export function realIP(ctr, name = '') {
|
|
|
304
304
|
const req = ctr.getPrototype('_req');
|
|
305
305
|
return req.socket.remoteAddress ?? '';
|
|
306
306
|
}
|
|
307
|
-
// --- 以下 Mutton 没有 ---
|
|
308
307
|
/**
|
|
309
308
|
* --- 间隔一段时间 ---
|
|
310
309
|
* @param ms 间隔毫秒
|
|
@@ -711,7 +710,7 @@ export async function ls(opt) {
|
|
|
711
710
|
return j.data;
|
|
712
711
|
}
|
|
713
712
|
/**
|
|
714
|
-
* ---
|
|
713
|
+
* --- 完整的克隆一份数组/对象 ---
|
|
715
714
|
* @param obj 要克隆的对象
|
|
716
715
|
*/
|
|
717
716
|
export function clone(obj) {
|
package/lib/net.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ export declare function buildCookieQuery(cookie: Record<string, ICookie>, uri: k
|
|
|
70
70
|
*/
|
|
71
71
|
export declare function resetCookieSession(cookie: Record<string, ICookie>): void;
|
|
72
72
|
/**
|
|
73
|
-
* --- 创建 FormData
|
|
73
|
+
* --- 创建 FormData 对象 ---
|
|
74
74
|
*/
|
|
75
75
|
export declare function getFormData(): fd.FormData;
|
|
76
76
|
/**
|
|
@@ -80,7 +80,7 @@ export declare function getFormData(): fd.FormData;
|
|
|
80
80
|
*/
|
|
81
81
|
export declare function filterProxyHeaders(headers: http.IncomingHttpHeaders | http2.IncomingHttpHeaders | THttpHeaders, res?: http2.Http2ServerResponse | http.ServerResponse): Record<string, string | string[]>;
|
|
82
82
|
/**
|
|
83
|
-
* --- 正向 mproxy
|
|
83
|
+
* --- 正向 mproxy 代理,注意提前处理不要自动处理 post 数据,读取 get 的 url 为实际请求地址 ---
|
|
84
84
|
* --- get: url, auth ---
|
|
85
85
|
* @param ctr 当前控制器
|
|
86
86
|
* @param auth 校验字符串,读取 get 的 auth 和本参数做比对
|
|
@@ -93,7 +93,7 @@ export declare function mproxy(ctr: sCtr.Ctr, auth: string, opt?: IMproxyOptions
|
|
|
93
93
|
*/
|
|
94
94
|
export declare function mproxyData(ctr: sCtr.Ctr): any;
|
|
95
95
|
/**
|
|
96
|
-
* ---
|
|
96
|
+
* --- 反向代理,注意提前处理不要自动处理 post 数据,将本服务器的某个路由反代到其他网址 ---
|
|
97
97
|
* @param ctr 当前控制器
|
|
98
98
|
* @param route 要反代的路由
|
|
99
99
|
* @param opt 参数
|
package/lib/net.js
CHANGED
|
@@ -423,7 +423,7 @@ export function resetCookieSession(cookie) {
|
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
425
|
/**
|
|
426
|
-
* --- 创建 FormData
|
|
426
|
+
* --- 创建 FormData 对象 ---
|
|
427
427
|
*/
|
|
428
428
|
export function getFormData() {
|
|
429
429
|
return new fd.FormData();
|
|
@@ -457,7 +457,7 @@ export function filterProxyHeaders(headers, res) {
|
|
|
457
457
|
return heads;
|
|
458
458
|
}
|
|
459
459
|
/**
|
|
460
|
-
* --- 正向 mproxy
|
|
460
|
+
* --- 正向 mproxy 代理,注意提前处理不要自动处理 post 数据,读取 get 的 url 为实际请求地址 ---
|
|
461
461
|
* --- get: url, auth ---
|
|
462
462
|
* @param ctr 当前控制器
|
|
463
463
|
* @param auth 校验字符串,读取 get 的 auth 和本参数做比对
|
|
@@ -466,7 +466,6 @@ export function filterProxyHeaders(headers, res) {
|
|
|
466
466
|
export async function mproxy(ctr, auth, opt = {}) {
|
|
467
467
|
const req = ctr.getPrototype('_req');
|
|
468
468
|
const res = ctr.getPrototype('_res');
|
|
469
|
-
const input = ctr.getPrototype('_input');
|
|
470
469
|
/** --- 客户端请求中的 get 的数据 --- */
|
|
471
470
|
const get = ctr.getPrototype('_get');
|
|
472
471
|
if (get['auth'] !== auth) {
|
|
@@ -479,7 +478,7 @@ export async function mproxy(ctr, auth, opt = {}) {
|
|
|
479
478
|
opt.headers ??= {};
|
|
480
479
|
Object.assign(opt.headers, filterProxyHeaders(req.headers));
|
|
481
480
|
// --- 发起请求 ---
|
|
482
|
-
const rres = await request(get['url'], req
|
|
481
|
+
const rres = await request(get['url'], req, opt);
|
|
483
482
|
if (rres.error) {
|
|
484
483
|
return -2;
|
|
485
484
|
}
|
|
@@ -510,7 +509,7 @@ export function mproxyData(ctr) {
|
|
|
510
509
|
return data;
|
|
511
510
|
}
|
|
512
511
|
/**
|
|
513
|
-
* ---
|
|
512
|
+
* --- 反向代理,注意提前处理不要自动处理 post 数据,将本服务器的某个路由反代到其他网址 ---
|
|
514
513
|
* @param ctr 当前控制器
|
|
515
514
|
* @param route 要反代的路由
|
|
516
515
|
* @param opt 参数
|
|
@@ -519,7 +518,6 @@ export async function rproxy(ctr, route, opt = {}) {
|
|
|
519
518
|
const req = ctr.getPrototype('_req');
|
|
520
519
|
const res = ctr.getPrototype('_res');
|
|
521
520
|
const config = ctr.getPrototype('_config');
|
|
522
|
-
const input = ctr.getPrototype('_input');
|
|
523
521
|
const path = config.const.path + (config.const.qs ? '?' + config.const.qs : '');
|
|
524
522
|
for (const key in route) {
|
|
525
523
|
if (!path.startsWith(key)) {
|
|
@@ -534,7 +532,7 @@ export async function rproxy(ctr, route, opt = {}) {
|
|
|
534
532
|
opt.headers ??= {};
|
|
535
533
|
Object.assign(opt.headers, filterProxyHeaders(req.headers));
|
|
536
534
|
// --- 发起请求 ---
|
|
537
|
-
const rres = await request(route[key] + lpath, req
|
|
535
|
+
const rres = await request(route[key] + lpath, req, opt);
|
|
538
536
|
if (rres.error) {
|
|
539
537
|
return false;
|
|
540
538
|
}
|
package/lib/text.d.ts
CHANGED
|
@@ -118,17 +118,17 @@ export declare function isRealPath(path: string): boolean;
|
|
|
118
118
|
*/
|
|
119
119
|
export declare function getFilename(path: string): string;
|
|
120
120
|
/**
|
|
121
|
-
* --- 将普通的返回 JSON
|
|
121
|
+
* --- 将普通的返回 JSON 对象序列化为字符串 ---
|
|
122
122
|
* @param o 返回 JSON 对象
|
|
123
123
|
*/
|
|
124
124
|
export declare function stringifyResult(rtn: kebab.Json): string;
|
|
125
125
|
/**
|
|
126
|
-
* --- 将字符串解析为对象,返回 false 代表解析失败,支持 BigInt
|
|
126
|
+
* --- 将字符串解析为对象,返回 false 代表解析失败,支持 BigInt ---
|
|
127
127
|
* @param str 要解析的 json 字符串
|
|
128
128
|
*/
|
|
129
129
|
export declare function parseJson(str: string): any;
|
|
130
130
|
/**
|
|
131
|
-
* --- 将对象转换为 json 字符串,返回 false 代表解析失败,支持 BigInt
|
|
131
|
+
* --- 将对象转换为 json 字符串,返回 false 代表解析失败,支持 BigInt ---
|
|
132
132
|
* @param obj 要转换的 json 对象
|
|
133
133
|
* @param space 美化方式
|
|
134
134
|
*/
|
|
@@ -138,6 +138,10 @@ export declare function stringifyJson(obj: kebab.Json, space?: string | number):
|
|
|
138
138
|
* @param buf 原始 buffer
|
|
139
139
|
*/
|
|
140
140
|
export declare function stringifyBuffer(buf: Buffer): string;
|
|
141
|
+
/**
|
|
142
|
+
* --- 递归删除 json 中的字符串首尾空格,会返回一个新的对象 ---
|
|
143
|
+
*/
|
|
144
|
+
export declare function trimJson(json: kebab.Json): kebab.Json;
|
|
141
145
|
type TFalsy = false | '' | 0 | null | undefined | typeof NaN;
|
|
142
146
|
/**
|
|
143
147
|
* --- 判断一个值是否是虚假的(为 null/undefined/空字符串/false/0) ---
|
package/lib/text.js
CHANGED
|
@@ -339,7 +339,6 @@ export function isIdCardCN(idcard) {
|
|
|
339
339
|
return false;
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
|
-
// --- 以下 Mutton: false, Kebab: true ---
|
|
343
342
|
/**
|
|
344
343
|
* --- 将对象转换为 query string ---
|
|
345
344
|
* @param query 要转换的对象
|
|
@@ -430,7 +429,7 @@ export function getFilename(path) {
|
|
|
430
429
|
return path.slice(lio + 1);
|
|
431
430
|
}
|
|
432
431
|
/**
|
|
433
|
-
* --- 将普通的返回 JSON
|
|
432
|
+
* --- 将普通的返回 JSON 对象序列化为字符串 ---
|
|
434
433
|
* @param o 返回 JSON 对象
|
|
435
434
|
*/
|
|
436
435
|
export function stringifyResult(rtn) {
|
|
@@ -469,7 +468,7 @@ export function stringifyResult(rtn) {
|
|
|
469
468
|
return JSON.stringify(rtn);
|
|
470
469
|
}
|
|
471
470
|
/**
|
|
472
|
-
* --- 将字符串解析为对象,返回 false 代表解析失败,支持 BigInt
|
|
471
|
+
* --- 将字符串解析为对象,返回 false 代表解析失败,支持 BigInt ---
|
|
473
472
|
* @param str 要解析的 json 字符串
|
|
474
473
|
*/
|
|
475
474
|
export function parseJson(str) {
|
|
@@ -497,7 +496,7 @@ export function parseJson(str) {
|
|
|
497
496
|
}
|
|
498
497
|
}
|
|
499
498
|
/**
|
|
500
|
-
* --- 将对象转换为 json 字符串,返回 false 代表解析失败,支持 BigInt
|
|
499
|
+
* --- 将对象转换为 json 字符串,返回 false 代表解析失败,支持 BigInt ---
|
|
501
500
|
* @param obj 要转换的 json 对象
|
|
502
501
|
* @param space 美化方式
|
|
503
502
|
*/
|
|
@@ -517,6 +516,25 @@ export function stringifyBuffer(buf) {
|
|
|
517
516
|
const arr = buf.toString('hex').match(/.{1,2}/g);
|
|
518
517
|
return `<Buffer ${arr ? arr.join(' ') : ''}>`;
|
|
519
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* --- 递归删除 json 中的字符串首尾空格,会返回一个新的对象 ---
|
|
521
|
+
*/
|
|
522
|
+
export function trimJson(json) {
|
|
523
|
+
json = Object.assign({}, json);
|
|
524
|
+
trimJsonRecursion(json);
|
|
525
|
+
return json;
|
|
526
|
+
}
|
|
527
|
+
function trimJsonRecursion(json) {
|
|
528
|
+
for (const key in json) {
|
|
529
|
+
const val = json[key];
|
|
530
|
+
if (typeof val === 'string') {
|
|
531
|
+
json[key] = val.trim();
|
|
532
|
+
}
|
|
533
|
+
else if (typeof val === 'object') {
|
|
534
|
+
trimJsonRecursion(val);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
520
538
|
/**
|
|
521
539
|
* --- 判断一个值是否是虚假的(为 null/undefined/空字符串/false/0) ---
|
|
522
540
|
* @param val 要判断的值
|
package/package.json
CHANGED
package/sys/ctr.d.ts
CHANGED
|
@@ -124,6 +124,8 @@ export declare class Ctr {
|
|
|
124
124
|
* --- WebSocket 下连接被终止后会自动被调用的事件,可重写此方法 ---
|
|
125
125
|
*/
|
|
126
126
|
onClose(): void | Promise<void>;
|
|
127
|
+
/** --- 请求发送开始时调用,返回 false 则框架不会自动获取任何 post 内容(仅会在 middle 内触发) --- */
|
|
128
|
+
onReqStart(): boolean | Promise<boolean>;
|
|
127
129
|
/**
|
|
128
130
|
* --- 获取截止当前时间的总运行时间 ---
|
|
129
131
|
* @param ms 为 true 为毫秒,否则为秒
|
package/sys/ctr.js
CHANGED
|
@@ -47,7 +47,6 @@ export class Ctr {
|
|
|
47
47
|
this._xsrf = '';
|
|
48
48
|
/** --- 自定义 http code --- */
|
|
49
49
|
this._httpCode = 0;
|
|
50
|
-
// --- Kebab: true,Mutton: false,全局常量等对象 ---
|
|
51
50
|
/** --- 当前语言名 --- */
|
|
52
51
|
this._locale = 'en';
|
|
53
52
|
/** --- 本 ctr 已加载的语言文件列表 --- */
|
|
@@ -164,6 +163,10 @@ export class Ctr {
|
|
|
164
163
|
onClose() {
|
|
165
164
|
return;
|
|
166
165
|
}
|
|
166
|
+
/** --- 请求发送开始时调用,返回 false 则框架不会自动获取任何 post 内容(仅会在 middle 内触发) --- */
|
|
167
|
+
onReqStart() {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
167
170
|
/**
|
|
168
171
|
* --- 获取截止当前时间的总运行时间 ---
|
|
169
172
|
* @param ms 为 true 为毫秒,否则为秒
|
|
@@ -658,7 +661,6 @@ export class Ctr {
|
|
|
658
661
|
}
|
|
659
662
|
return true;
|
|
660
663
|
}
|
|
661
|
-
// --- 以下:Mutton: false, Kebab: true ---
|
|
662
664
|
/**
|
|
663
665
|
* --- 获取语言包值 ---
|
|
664
666
|
* @param key
|
package/sys/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Project:
|
|
2
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-6-4 21:35
|
|
4
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, 2025-9-23 11:01:36
|
|
5
5
|
*/
|
|
@@ -58,7 +58,7 @@ export default class Mod {
|
|
|
58
58
|
protected _db: lDb.Pool | lDb.Transaction;
|
|
59
59
|
/** --- Sql 对象 --- */
|
|
60
60
|
protected _sql: lSql.Sql;
|
|
61
|
-
/** --- ctr
|
|
61
|
+
/** --- ctr 对象 --- */
|
|
62
62
|
protected _ctr?: sCtr.Ctr;
|
|
63
63
|
/**
|
|
64
64
|
* --- 构造函数 ---
|
package/sys/mod.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Project:
|
|
2
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-6-4 21:35
|
|
4
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, 2025-9-23 11:01:36
|
|
5
5
|
*/
|
|
@@ -89,7 +89,7 @@ class Mod {
|
|
|
89
89
|
this._contain = null;
|
|
90
90
|
/** --- 已算出的 total --- */
|
|
91
91
|
this._total = [];
|
|
92
|
-
/** --- ctr
|
|
92
|
+
/** --- ctr 对象 --- */
|
|
93
93
|
this._ctr = undefined;
|
|
94
94
|
/** --- 设置的 limit --- */
|
|
95
95
|
this._limit = [0, 0];
|
package/sys/route.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare function run(data: {
|
|
|
35
35
|
};
|
|
36
36
|
}): Promise<boolean>;
|
|
37
37
|
/**
|
|
38
|
-
* ---
|
|
38
|
+
* --- 删除本次请求所有已上传的临时文件 ---
|
|
39
39
|
* @param cctr Ctr 对象 或 files
|
|
40
40
|
*/
|
|
41
41
|
export declare function unlinkUploadFiles(cctr: sCtr.Ctr | Record<string, kebab.IPostFile | kebab.IPostFile[]>): Promise<void>;
|
|
@@ -46,10 +46,14 @@ export declare function unlinkUploadFiles(cctr: sCtr.Ctr | Record<string, kebab.
|
|
|
46
46
|
*/
|
|
47
47
|
export declare function waitCtr(cctr: sCtr.Ctr): Promise<void>;
|
|
48
48
|
/**
|
|
49
|
-
* ---
|
|
50
|
-
* @param
|
|
49
|
+
* --- 获取 post 对象(通常已自动获取),如果是文件上传(formdata)的情况则不获取 ---
|
|
50
|
+
* @param req 请求对象
|
|
51
51
|
*/
|
|
52
|
-
export declare function
|
|
52
|
+
export declare function getPost(req: http2.Http2ServerRequest | http.IncomingMessage): Promise<{
|
|
53
|
+
'input': string;
|
|
54
|
+
'raw': Record<string, any>;
|
|
55
|
+
'post': Record<string, any>;
|
|
56
|
+
}>;
|
|
53
57
|
/**
|
|
54
58
|
* --- 获取 formdata 的 post ---
|
|
55
59
|
* @param req 请求头
|
package/sys/route.js
CHANGED
|
@@ -365,18 +365,18 @@ export async function run(data) {
|
|
|
365
365
|
middle.setPrototype('_action', pathRight);
|
|
366
366
|
middle.setPrototype('_headers', headers);
|
|
367
367
|
middle.setPrototype('_get', get);
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
368
|
+
/** --- 是否让框架自动获取 post,true 为自动(默认) --- */
|
|
369
|
+
const reqStartRtn = await middle.onReqStart();
|
|
370
|
+
if (reqStartRtn) {
|
|
371
|
+
const rawPost = await getPost(data.req);
|
|
372
|
+
// --- 原始 POST ---
|
|
373
|
+
middle.setPrototype('_rawPost', rawPost.raw);
|
|
374
|
+
// --- 原始 input ---
|
|
375
|
+
middle.setPrototype('_input', rawPost.input);
|
|
376
|
+
// --- 处理后的 post ---
|
|
377
|
+
middle.setPrototype('_post', rawPost.post);
|
|
378
|
+
// --- form data 格式交由用户自行获取,可以直接获取文件流,然后做他想做的事情 ---
|
|
379
|
+
}
|
|
380
380
|
// --- 执行中间控制器的 onLoad ---
|
|
381
381
|
try {
|
|
382
382
|
rtn = await middle.onLoad();
|
|
@@ -717,7 +717,7 @@ function getPathLeftRight(path) {
|
|
|
717
717
|
return [path.slice(0, pathLio), right === '' ? 'index' : right];
|
|
718
718
|
}
|
|
719
719
|
/**
|
|
720
|
-
* --- 根据 path 获取 ws
|
|
720
|
+
* --- 根据 path 获取 ws 的控制器类名 ---
|
|
721
721
|
* @param path 路径
|
|
722
722
|
*/
|
|
723
723
|
function getWsCtrName(path) {
|
|
@@ -728,7 +728,7 @@ function getWsCtrName(path) {
|
|
|
728
728
|
return path.slice(pathLio + 1).toLowerCase();
|
|
729
729
|
}
|
|
730
730
|
/**
|
|
731
|
-
* ---
|
|
731
|
+
* --- 删除本次请求所有已上传的临时文件 ---
|
|
732
732
|
* @param cctr Ctr 对象 或 files
|
|
733
733
|
*/
|
|
734
734
|
export async function unlinkUploadFiles(cctr) {
|
|
@@ -765,29 +765,18 @@ export async function waitCtr(cctr) {
|
|
|
765
765
|
await unlinkUploadFiles(cctr);
|
|
766
766
|
}
|
|
767
767
|
/**
|
|
768
|
-
* ---
|
|
769
|
-
* @param post
|
|
770
|
-
*/
|
|
771
|
-
export function trimPost(post) {
|
|
772
|
-
for (const key in post) {
|
|
773
|
-
const val = post[key];
|
|
774
|
-
if (typeof val === 'string') {
|
|
775
|
-
post[key] = post[key].trim();
|
|
776
|
-
}
|
|
777
|
-
else if (typeof val === 'object') {
|
|
778
|
-
trimPost(post[key]);
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* --- 内部使用,获取 post 对象,如果是文件上传(formdata)的情况则不获取 ---
|
|
768
|
+
* --- 获取 post 对象(通常已自动获取),如果是文件上传(formdata)的情况则不获取 ---
|
|
784
769
|
* @param req 请求对象
|
|
785
770
|
*/
|
|
786
|
-
function getPost(req) {
|
|
771
|
+
export function getPost(req) {
|
|
787
772
|
return new Promise(function (resolve) {
|
|
788
773
|
const ct = req.headers['content-type'] ?? '';
|
|
789
774
|
if (ct.includes('form-data')) {
|
|
790
|
-
resolve(
|
|
775
|
+
resolve({
|
|
776
|
+
'input': '',
|
|
777
|
+
'raw': {},
|
|
778
|
+
'post': {},
|
|
779
|
+
});
|
|
791
780
|
return;
|
|
792
781
|
}
|
|
793
782
|
// --- json 或普通 post ---
|
|
@@ -798,20 +787,38 @@ function getPost(req) {
|
|
|
798
787
|
req.on('end', function () {
|
|
799
788
|
const s = buffer.toString();
|
|
800
789
|
if (!s) {
|
|
801
|
-
resolve(
|
|
790
|
+
resolve({
|
|
791
|
+
'input': '',
|
|
792
|
+
'raw': {},
|
|
793
|
+
'post': {},
|
|
794
|
+
});
|
|
802
795
|
return;
|
|
803
796
|
}
|
|
804
797
|
// --- 判断 json 还是普通 ---
|
|
805
798
|
if (ct.includes('json')) {
|
|
806
799
|
try {
|
|
807
|
-
|
|
800
|
+
const raw = lText.parseJson(s);
|
|
801
|
+
resolve({
|
|
802
|
+
'input': s,
|
|
803
|
+
'raw': raw,
|
|
804
|
+
'post': lText.trimJson(raw),
|
|
805
|
+
});
|
|
808
806
|
}
|
|
809
807
|
catch {
|
|
810
|
-
resolve(
|
|
808
|
+
resolve({
|
|
809
|
+
'input': '',
|
|
810
|
+
'raw': {},
|
|
811
|
+
'post': {},
|
|
812
|
+
});
|
|
811
813
|
}
|
|
812
814
|
return;
|
|
813
815
|
}
|
|
814
|
-
|
|
816
|
+
const raw = lText.queryParse(s);
|
|
817
|
+
resolve({
|
|
818
|
+
'input': s,
|
|
819
|
+
'raw': raw,
|
|
820
|
+
'post': lText.trimJson(raw),
|
|
821
|
+
});
|
|
815
822
|
});
|
|
816
823
|
});
|
|
817
824
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as kebab from '#kebab/index.js';
|
|
2
2
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
3
3
|
export default class extends sCtr.Ctr {
|
|
4
|
+
onReqStart(): boolean;
|
|
4
5
|
onLoad(): string | boolean;
|
|
5
6
|
onUnload(rtn: string | boolean | kebab.DbValue[]): string | boolean | kebab.DbValue[];
|
|
6
7
|
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
2
2
|
export default class extends sCtr.Ctr {
|
|
3
|
+
onReqStart() {
|
|
4
|
+
if (this._config.const.path === 'test/net-mproxy1') {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
if (this._config.const.path.startsWith('test/net-rproxy/')) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
3
12
|
onLoad() {
|
|
4
13
|
if (this._config.const.path !== 'test/middle') {
|
|
5
14
|
return true;
|
package/www/example/ctr/test.js
CHANGED
|
@@ -1785,14 +1785,14 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
1785
1785
|
'mproxy': {
|
|
1786
1786
|
'url': this._internalUrl + 'test/net-mproxy1',
|
|
1787
1787
|
'auth': '123456',
|
|
1788
|
-
'data': { 'test': '123' }
|
|
1788
|
+
'data': { 'test': '123' },
|
|
1789
1789
|
}
|
|
1790
1790
|
});
|
|
1791
1791
|
echo.push(`<pre>lNet.get('https://cdn.jsdelivr.net/npm/deskrt@2.0.10/package.json', {
|
|
1792
1792
|
'mproxy': {
|
|
1793
1793
|
'url': '${this._internalUrl}test/net-mproxy1',
|
|
1794
1794
|
'auth': '123456',
|
|
1795
|
-
'data': { 'test': '123' }
|
|
1795
|
+
'data': { 'test': '123' },
|
|
1796
1796
|
}
|
|
1797
1797
|
});</pre>
|
|
1798
1798
|
headers: <pre>${JSON.stringify(res.headers, null, 4)}</pre>
|
package/tsconfig.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "esnext",
|
|
4
|
-
"removeComments": false,
|
|
5
|
-
"preserveConstEnums": true, // 保留 const 和 enum 声明
|
|
6
|
-
"outDir": "./",
|
|
7
|
-
"sourceMap": false,
|
|
8
|
-
"target": "ES2021",
|
|
9
|
-
"strict": true, // 严格模式
|
|
10
|
-
"declaration": true, // d.ts
|
|
11
|
-
"declarationMap": false, // d.ts 的 map
|
|
12
|
-
"newLine": "LF",
|
|
13
|
-
"paths": {
|
|
14
|
-
"#kebab/*": ["./*"]
|
|
15
|
-
},
|
|
16
|
-
"moduleResolution": "node",
|
|
17
|
-
"resolveJsonModule": true,
|
|
18
|
-
"esModuleInterop": true
|
|
19
|
-
},
|
|
20
|
-
"include": [
|
|
21
|
-
"./**/*.ts"
|
|
22
|
-
],
|
|
23
|
-
"exclude": [
|
|
24
|
-
"node_modules"
|
|
25
|
-
]
|
|
26
|
-
}
|