@maiyunnet/kebab 3.1.4 → 3.1.5
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 +147 -1
- package/index.js +2 -1
- package/lib/core.d.ts +5 -5
- package/lib/core.js +1 -1
- package/lib/db.d.ts +12 -12
- package/lib/db.js +0 -1
- package/lib/jwt.d.ts +8 -8
- package/lib/jwt.js +0 -1
- package/lib/kv.d.ts +41 -41
- package/lib/kv.js +0 -1
- package/lib/net/request.d.ts +5 -5
- package/lib/net/request.js +2 -2
- package/lib/net/response.d.ts +5 -5
- package/lib/net.d.ts +79 -62
- package/lib/net.js +20 -20
- package/lib/sql.d.ts +20 -20
- package/lib/sql.js +0 -5
- package/lib/text.d.ts +9 -4
- package/lib/text.js +3 -3
- package/lib/ws.d.ts +8 -7
- package/lib/ws.js +0 -1
- package/lib/zip.d.ts +55 -11
- package/package.json +5 -4
- package/sys/child.js +1 -1
- package/sys/ctr.d.ts +24 -24
- package/sys/ctr.js +15 -15
- package/sys/mod.d.ts +40 -26
- package/sys/mod.js +1 -1
- package/sys/route.d.ts +7 -7
- package/sys/route.js +1 -1
- package/www/example/ctr/main.d.ts +2 -2
- package/www/example/ctr/main.js +2 -2
- package/www/example/ctr/middle.d.ts +4 -4
- package/www/example/ctr/middle.js +2 -2
- package/www/example/ctr/test.d.ts +24 -24
- package/www/example/ctr/test.js +2 -2
- package/www/example/mod/test.d.ts +2 -2
- package/types/index.d.ts +0 -284
package/lib/ws.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-6-2 20:42
|
|
4
|
-
* Last: 2020-4-9 22:33:11, 2022-09-13 13:32:01, 2022-12-30 19:13:07, 2024-2-6 23:53:45, 2024-12-23 01:33:16, 2025-1-28 21:05:51
|
|
4
|
+
* Last: 2020-4-9 22:33:11, 2022-09-13 13:32:01, 2022-12-30 19:13:07, 2024-2-6 23:53:45, 2024-12-23 01:33:16, 2025-1-28 21:05:51, 2025-9-23 12:27:48
|
|
5
5
|
*/
|
|
6
6
|
import * as http from 'http';
|
|
7
7
|
import * as net from 'net';
|
|
8
|
-
import * as
|
|
8
|
+
import * as kebab from '#index.js';
|
|
9
|
+
import * as lNet from '#lib/net.js';
|
|
9
10
|
import * as sCtr from '#sys/ctr.js';
|
|
10
11
|
/** --- 一般用 SIMPLE --- */
|
|
11
12
|
export declare enum EFrameReceiveMode {
|
|
@@ -28,9 +29,9 @@ export interface IConnectOptions {
|
|
|
28
29
|
'timeout'?: number;
|
|
29
30
|
'hosts'?: Record<string, string>;
|
|
30
31
|
'local'?: string;
|
|
31
|
-
'headers'?:
|
|
32
|
+
'headers'?: lNet.THttpHeaders;
|
|
32
33
|
/** --- cookie 托管对象 --- */
|
|
33
|
-
'cookie'?: Record<string,
|
|
34
|
+
'cookie'?: Record<string, lNet.ICookie>;
|
|
34
35
|
/** --- 小帧模式,默认 false --- */
|
|
35
36
|
'mode'?: EFrameReceiveMode;
|
|
36
37
|
/** --- 加密模式,默认 true --- */
|
|
@@ -47,7 +48,7 @@ export interface IMproxyOptions {
|
|
|
47
48
|
'timeout'?: number;
|
|
48
49
|
'hosts'?: Record<string, string>;
|
|
49
50
|
'local'?: string;
|
|
50
|
-
'headers'?:
|
|
51
|
+
'headers'?: lNet.THttpHeaders;
|
|
51
52
|
/** --- 小帧模式,默认 false --- */
|
|
52
53
|
'mode'?: EFrameReceiveMode;
|
|
53
54
|
/** --- 加密模式,默认 true --- */
|
|
@@ -59,7 +60,7 @@ export interface IRproxyOptions {
|
|
|
59
60
|
'timeout'?: number;
|
|
60
61
|
'hosts'?: Record<string, string>;
|
|
61
62
|
'local'?: string;
|
|
62
|
-
'headers'?:
|
|
63
|
+
'headers'?: lNet.THttpHeaders;
|
|
63
64
|
/** --- 小帧模式,默认 false --- */
|
|
64
65
|
'mode'?: EFrameReceiveMode;
|
|
65
66
|
/** --- 加密模式,默认 true --- */
|
|
@@ -105,7 +106,7 @@ export declare class Socket {
|
|
|
105
106
|
/** --- 发送文本 --- */
|
|
106
107
|
writeText(data: string): boolean;
|
|
107
108
|
/** --- 发送结果对象字符串 --- */
|
|
108
|
-
writeResult(data:
|
|
109
|
+
writeResult(data: kebab.Json): boolean;
|
|
109
110
|
/** --- 发送二进制 --- */
|
|
110
111
|
writeBinary(data: string | Buffer | Array<string | Buffer>): boolean;
|
|
111
112
|
/** --- 当前是否是可写状态 --- */
|
package/lib/ws.js
CHANGED
package/lib/zip.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import jszip from 'jszip';
|
|
2
|
-
import * as types from '#types/index.js';
|
|
3
2
|
/**
|
|
4
3
|
* --- 本库主要用于读取 zip,请尽量不要用来写入 zip,尤其是大文件 zip ---
|
|
5
4
|
*/
|
|
@@ -10,14 +9,14 @@ export declare class Zip {
|
|
|
10
9
|
private _path;
|
|
11
10
|
constructor(zip: jszip);
|
|
12
11
|
getContent(path: string): Promise<string | null>;
|
|
13
|
-
getContent<T extends
|
|
12
|
+
getContent<T extends TZipOutputType>(path: string, type: T): Promise<IZipOutputByType[T] | null>;
|
|
14
13
|
/**
|
|
15
14
|
* --- 写入文件内容 ---
|
|
16
15
|
* @param path 文件路径
|
|
17
16
|
* @param data 要写入的内容
|
|
18
17
|
* @param options 选项
|
|
19
18
|
*/
|
|
20
|
-
putContent<T extends
|
|
19
|
+
putContent<T extends TZipInputType>(path: string, data: IZipInputByType[T], options?: {
|
|
21
20
|
'base64'?: boolean;
|
|
22
21
|
'binary'?: boolean;
|
|
23
22
|
'date'?: Date;
|
|
@@ -32,28 +31,28 @@ export declare class Zip {
|
|
|
32
31
|
* @param path 对象路径
|
|
33
32
|
* @param options 选项
|
|
34
33
|
*/
|
|
35
|
-
stats(path: string):
|
|
34
|
+
stats(path: string): IZipStats | null;
|
|
36
35
|
/**
|
|
37
36
|
* --- 判断是否是目录或目录是否存在,是的话返回 stats ---
|
|
38
37
|
* @param path 判断路径
|
|
39
38
|
*/
|
|
40
|
-
isDir(path: string):
|
|
39
|
+
isDir(path: string): IZipStats | false;
|
|
41
40
|
/**
|
|
42
41
|
* --- 判断是否是文件或文件是否存在,是的话返回 stats ---
|
|
43
42
|
* @param path 判断路径
|
|
44
43
|
*/
|
|
45
|
-
isFile(path: string):
|
|
44
|
+
isFile(path: string): IZipStats | false;
|
|
46
45
|
/** --- 读取目录,hasChildren: false, hasDir: true, pathAsKey: false --- */
|
|
47
46
|
readDir(path?: string, opt?: {
|
|
48
47
|
'hasChildren'?: boolean;
|
|
49
48
|
'hasDir'?: boolean;
|
|
50
49
|
'pathAsKey'?: false;
|
|
51
|
-
}):
|
|
50
|
+
}): IZipItem[];
|
|
52
51
|
readDir(path?: string, opt?: {
|
|
53
52
|
'hasChildren'?: boolean;
|
|
54
53
|
'hasDir'?: boolean;
|
|
55
54
|
'pathAsKey': true;
|
|
56
|
-
}): Record<string,
|
|
55
|
+
}): Record<string, IZipItem>;
|
|
57
56
|
private _readDir;
|
|
58
57
|
/** --- 目录列表缓存 --- */
|
|
59
58
|
private _list;
|
|
@@ -76,11 +75,11 @@ export declare class Zip {
|
|
|
76
75
|
* --- 打包 zip ---
|
|
77
76
|
* @param options 选项
|
|
78
77
|
*/
|
|
79
|
-
generate<T extends
|
|
78
|
+
generate<T extends TZipOutputType>(options?: {
|
|
80
79
|
'type'?: T;
|
|
81
80
|
'level'?: number;
|
|
82
81
|
'onUpdate'?: (percent: number, currentFile: string | null) => void;
|
|
83
|
-
}): Promise<
|
|
82
|
+
}): Promise<IZipOutputByType[T]>;
|
|
84
83
|
/**
|
|
85
84
|
* --- 获取 path 和 string/Buffer 对应的文件列表 ---
|
|
86
85
|
*/
|
|
@@ -90,4 +89,49 @@ export declare class Zip {
|
|
|
90
89
|
* --- 获取 zip 对象 ---
|
|
91
90
|
* @param data 对象数据
|
|
92
91
|
*/
|
|
93
|
-
export declare function get(data?:
|
|
92
|
+
export declare function get(data?: TZipInputFileFormat): Promise<Zip | null>;
|
|
93
|
+
export interface IZipItem {
|
|
94
|
+
'name': string;
|
|
95
|
+
'compressedSize': number;
|
|
96
|
+
'uncompressedSize': number;
|
|
97
|
+
'date': Date;
|
|
98
|
+
'isFile': boolean;
|
|
99
|
+
'isDirectory': boolean;
|
|
100
|
+
'path': string;
|
|
101
|
+
}
|
|
102
|
+
export interface IZipStats {
|
|
103
|
+
'compressedSize': number;
|
|
104
|
+
'uncompressedSize': number;
|
|
105
|
+
'date': Date;
|
|
106
|
+
'isFile': boolean;
|
|
107
|
+
'isDirectory': boolean;
|
|
108
|
+
}
|
|
109
|
+
export interface IZipOutputByType {
|
|
110
|
+
'base64': string;
|
|
111
|
+
'string': string;
|
|
112
|
+
'text': string;
|
|
113
|
+
'binarystring': string;
|
|
114
|
+
'array': number[];
|
|
115
|
+
'uint8array': Uint8Array;
|
|
116
|
+
'arraybuffer': ArrayBuffer;
|
|
117
|
+
'blob': Blob;
|
|
118
|
+
'nodebuffer': Buffer;
|
|
119
|
+
}
|
|
120
|
+
export type TZipOutputType = keyof IZipOutputByType;
|
|
121
|
+
export interface IZipInputByType {
|
|
122
|
+
'base64': string;
|
|
123
|
+
'string': string;
|
|
124
|
+
'text': string;
|
|
125
|
+
'binarystring': string;
|
|
126
|
+
'array': number[];
|
|
127
|
+
'uint8array': Uint8Array;
|
|
128
|
+
'arraybuffer': ArrayBuffer;
|
|
129
|
+
'blob': Blob;
|
|
130
|
+
'nodebuffer': Buffer;
|
|
131
|
+
}
|
|
132
|
+
export type TZipInputType = keyof IZipInputByType;
|
|
133
|
+
export type TZipInputFileFormat = IZipInputByType[keyof IZipInputByType];
|
|
134
|
+
export interface IZipMetadata {
|
|
135
|
+
'percent': number;
|
|
136
|
+
'currentFile': string | null;
|
|
137
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maiyunnet/kebab",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.5",
|
|
4
4
|
"description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"main": "index.js",
|
|
12
12
|
"author": "hanguoshuai",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
|
+
"types": "./index.d.ts",
|
|
14
15
|
"bin": {
|
|
15
16
|
"kebab": "./bin/kebab.js"
|
|
16
17
|
},
|
|
@@ -18,8 +19,8 @@
|
|
|
18
19
|
"#*": "./*"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@aws-sdk/client-s3": "^3.
|
|
22
|
-
"@aws-sdk/lib-storage": "^3.
|
|
22
|
+
"@aws-sdk/client-s3": "^3.894.0",
|
|
23
|
+
"@aws-sdk/lib-storage": "^3.894.0",
|
|
23
24
|
"@litert/http-client": "^1.1.2",
|
|
24
25
|
"@litert/mime": "^0.1.3",
|
|
25
26
|
"@litert/redis": "^3.0.5",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"mysql2": "^3.15.0",
|
|
31
32
|
"ssh2": "^1.17.0",
|
|
32
33
|
"svg-captcha": "^1.4.0",
|
|
33
|
-
"tencentcloud-sdk-nodejs": "^4.1.
|
|
34
|
+
"tencentcloud-sdk-nodejs": "^4.1.120"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@litert/eslint-plugin-rules": "^0.3.1",
|
package/sys/child.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as http2 from 'http2';
|
|
|
7
7
|
import * as tls from 'tls';
|
|
8
8
|
import * as http from 'http';
|
|
9
9
|
import * as crypto from 'crypto';
|
|
10
|
-
// ---
|
|
10
|
+
// --- 库 ---
|
|
11
11
|
import * as fs from '#lib/fs.js';
|
|
12
12
|
import * as lCore from '#lib/core.js';
|
|
13
13
|
import * as lText from '#lib/text.js';
|
package/sys/ctr.d.ts
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import * as http from 'http';
|
|
7
7
|
import * as http2 from 'http2';
|
|
8
|
-
import * as
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
11
|
-
import * as
|
|
12
|
-
import * as
|
|
8
|
+
import * as kebab from '#index.js';
|
|
9
|
+
import * as lSession from '#lib/session.js';
|
|
10
|
+
import * as lDb from '#lib/db.js';
|
|
11
|
+
import * as lKv from '#lib/kv.js';
|
|
12
|
+
import * as lWs from '#lib/ws.js';
|
|
13
13
|
/**
|
|
14
14
|
* --- 清除已经加载的 data 与语言包文件缓存 ---
|
|
15
15
|
*/
|
|
@@ -24,13 +24,13 @@ export declare class Ctr {
|
|
|
24
24
|
/** --- GET 数据 --- */
|
|
25
25
|
protected _get: Record<string, string>;
|
|
26
26
|
/** --- 原始 POST 数据 --- */
|
|
27
|
-
protected _rawPost: Record<string,
|
|
27
|
+
protected _rawPost: Record<string, kebab.Json>;
|
|
28
28
|
/** --- POST 数据 --- */
|
|
29
|
-
protected _post: Record<string,
|
|
29
|
+
protected _post: Record<string, kebab.Json>;
|
|
30
30
|
/** --- 原始 input 字符串 */
|
|
31
31
|
protected _input: string;
|
|
32
32
|
/** --- 上传的文件列表 --- */
|
|
33
|
-
protected _files: Record<string,
|
|
33
|
+
protected _files: Record<string, kebab.IPostFile | kebab.IPostFile[]>;
|
|
34
34
|
/** --- Cookie 数组 --- */
|
|
35
35
|
protected _cookie: Record<string, string>;
|
|
36
36
|
/** --- Jwt 数组 --- */
|
|
@@ -38,7 +38,7 @@ export declare class Ctr {
|
|
|
38
38
|
/** --- Session 数组 --- */
|
|
39
39
|
protected _session: Record<string, any>;
|
|
40
40
|
/** --- Session --- 对象 */
|
|
41
|
-
protected _sess:
|
|
41
|
+
protected _sess: lSession.Session | null;
|
|
42
42
|
/** --- 页面浏览器客户端缓存 --- */
|
|
43
43
|
protected _cacheTTL: number;
|
|
44
44
|
/** --- XSRF TOKEN 值 --- */
|
|
@@ -48,7 +48,7 @@ export declare class Ctr {
|
|
|
48
48
|
/** --- 当前语言名 --- */
|
|
49
49
|
protected _locale: string;
|
|
50
50
|
/** --- vhost 的 kebab.json 以及全局常量 --- */
|
|
51
|
-
protected readonly _config:
|
|
51
|
+
protected readonly _config: kebab.IConfig;
|
|
52
52
|
protected readonly _req: http2.Http2ServerRequest | http.IncomingMessage;
|
|
53
53
|
protected readonly _res: http2.Http2ServerResponse | http.ServerResponse;
|
|
54
54
|
protected readonly _socket: lWs.Socket;
|
|
@@ -56,7 +56,7 @@ export declare class Ctr {
|
|
|
56
56
|
protected _localeFiles: string[];
|
|
57
57
|
/** --- 本 ctr 的 locale data --- */
|
|
58
58
|
protected _localeData: Record<string, Record<string, string>>;
|
|
59
|
-
constructor(config:
|
|
59
|
+
constructor(config: kebab.IConfig, req: http2.Http2ServerRequest | http.IncomingMessage, res?: http2.Http2ServerResponse | http.ServerResponse);
|
|
60
60
|
/** --- 当前用户连接是否还在连接中 --- */
|
|
61
61
|
get isAvail(): boolean;
|
|
62
62
|
/** --- timeout 的 timer --- */
|
|
@@ -79,26 +79,26 @@ export declare class Ctr {
|
|
|
79
79
|
*/
|
|
80
80
|
protected _asyncTask(func: () => void | Promise<void>): void;
|
|
81
81
|
/** --- 获取类内部的 prototype --- */
|
|
82
|
-
getPrototype(name: '_config'):
|
|
83
|
-
getPrototype(name: '_sess'):
|
|
82
|
+
getPrototype(name: '_config'): kebab.IConfig;
|
|
83
|
+
getPrototype(name: '_sess'): lSession.Session | null;
|
|
84
84
|
getPrototype(name: '_headers'): http.IncomingHttpHeaders;
|
|
85
85
|
getPrototype(name: '_req'): http2.Http2ServerRequest | http.IncomingMessage;
|
|
86
86
|
getPrototype(name: '_res'): http2.Http2ServerResponse | http.ServerResponse;
|
|
87
87
|
getPrototype(name: '_socket'): lWs.Socket;
|
|
88
|
-
getPrototype(name: '_rawPost' | '_post' | '_get' | '_session'): Record<string,
|
|
88
|
+
getPrototype(name: '_rawPost' | '_post' | '_get' | '_session'): Record<string, kebab.Json>;
|
|
89
89
|
getPrototype(name: '_input'): string;
|
|
90
|
-
getPrototype(name: string):
|
|
90
|
+
getPrototype(name: string): kebab.Json;
|
|
91
91
|
/** --- 设置类内部的 prototype --- */
|
|
92
|
-
setPrototype(name: string, val: string | string[] | http.IncomingHttpHeaders | Record<string,
|
|
92
|
+
setPrototype(name: string, val: string | string[] | http.IncomingHttpHeaders | Record<string, kebab.Json> | lSession.Session | lWs.Socket | null): void;
|
|
93
93
|
/**
|
|
94
94
|
* --- 实例化后会执行的方法,可重写此方法 ---
|
|
95
95
|
*/
|
|
96
|
-
onLoad(): boolean | string |
|
|
96
|
+
onLoad(): boolean | string | kebab.DbValue[] | Promise<boolean | string | kebab.DbValue[]>;
|
|
97
97
|
/**
|
|
98
98
|
* --- 整个结束前会执行本方法,可重写此方法对输出结果再处理一次(Websocket 模式无效) ---
|
|
99
99
|
* @param rtn 之前用户的输出结果
|
|
100
100
|
*/
|
|
101
|
-
onUnload(rtn: boolean | string |
|
|
101
|
+
onUnload(rtn: boolean | string | kebab.DbValue[]): boolean | string | kebab.DbValue[] | Promise<boolean | string | kebab.DbValue[]>;
|
|
102
102
|
/**
|
|
103
103
|
* --- WebSocket 下在建立 Server 连接之前可对 WebSocket 的信息进行配置 ---
|
|
104
104
|
*/
|
|
@@ -109,7 +109,7 @@ export declare class Ctr {
|
|
|
109
109
|
/**
|
|
110
110
|
* --- WebSocket 下当收到数据时会自动被调用的事件,即只文本和二进制数据,返回内容会被发送给 socket,但返回 false 连接会被中断 ---
|
|
111
111
|
*/
|
|
112
|
-
onData(data: Buffer | string, opcode: lWs.EOpcode):
|
|
112
|
+
onData(data: Buffer | string, opcode: lWs.EOpcode): kebab.Json;
|
|
113
113
|
/**
|
|
114
114
|
* --- 包含所有 opcode 的消息,若要发送数据需自行调用 write 方法,返回 false 则不会执行默认方法 ---
|
|
115
115
|
* @param data 数据
|
|
@@ -138,21 +138,21 @@ export declare class Ctr {
|
|
|
138
138
|
* @param path
|
|
139
139
|
* @param data
|
|
140
140
|
*/
|
|
141
|
-
protected _loadView(path: string, data?:
|
|
141
|
+
protected _loadView(path: string, data?: kebab.Json): Promise<string>;
|
|
142
142
|
/**
|
|
143
143
|
* --- 检测提交的数据类型 ---
|
|
144
144
|
* @param input 要校验的输入项
|
|
145
145
|
* @param rule 规则
|
|
146
146
|
* @param rtn 返回值
|
|
147
147
|
*/
|
|
148
|
-
protected _checkInput(input: Record<string,
|
|
148
|
+
protected _checkInput(input: Record<string, kebab.Json>, rule: Record<string, kebab.Json[]>, rtn: kebab.Json[]): boolean;
|
|
149
149
|
/**
|
|
150
150
|
* --- 检测提交的数据类型(会检测 XSRF) ---
|
|
151
151
|
* @param input 要校验的输入项
|
|
152
152
|
* @param rule 规则
|
|
153
153
|
* @param rtn 返回值
|
|
154
154
|
*/
|
|
155
|
-
protected _checkXInput(input: Record<string,
|
|
155
|
+
protected _checkXInput(input: Record<string, kebab.Json>, rule: Record<string, kebab.Json[]>, rtn: kebab.Json[]): boolean;
|
|
156
156
|
/**
|
|
157
157
|
* --- 当前页面开启 XSRF 支持(主要检测 cookie 是否存在) ---
|
|
158
158
|
* --- 如果当前页面有 CDN,请不要使用 ---
|
|
@@ -193,7 +193,7 @@ export declare class Ctr {
|
|
|
193
193
|
* @param auth 设为 true 则从头 Authorization 或 post _auth 值读取 token
|
|
194
194
|
* @param opt name, ttl, ssl, sqlPre
|
|
195
195
|
*/
|
|
196
|
-
protected _startSession(link:
|
|
196
|
+
protected _startSession(link: lDb.Pool | lKv.Pool, auth?: boolean, opt?: lSession.IOptions): Promise<void>;
|
|
197
197
|
/**
|
|
198
198
|
* --- 设定语言并加载语言包 ---
|
|
199
199
|
* @param loc 要加载的目标语言
|
|
@@ -230,7 +230,7 @@ export declare class Ctr {
|
|
|
230
230
|
* --- 发送结果对象文本 ---
|
|
231
231
|
* @param data 要发送的结果对象,如 [0, 'Failed.']
|
|
232
232
|
*/
|
|
233
|
-
protected _writeResult(data:
|
|
233
|
+
protected _writeResult(data: kebab.Json): boolean;
|
|
234
234
|
/**
|
|
235
235
|
* --- 发送 socket 二进制 ---
|
|
236
236
|
* @param data 要发送的信息
|
package/sys/ctr.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as ejs from 'ejs';
|
|
2
|
-
import * as lCore from '
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
7
|
-
import * as sRoute from '
|
|
2
|
+
import * as lCore from '#lib/core.js';
|
|
3
|
+
import * as lFs from '#lib/fs.js';
|
|
4
|
+
import * as lCrypto from '#lib/crypto.js';
|
|
5
|
+
import * as lSession from '#lib/session.js';
|
|
6
|
+
import * as lText from '#lib/text.js';
|
|
7
|
+
import * as sRoute from '#sys/route.js';
|
|
8
8
|
/** --- 已加载的 DATA 数据缓存(不是语言包)-- */
|
|
9
9
|
let loadedData = {};
|
|
10
10
|
/** --- 已加载的语言文件列表 --- */
|
|
@@ -112,7 +112,7 @@ export class Ctr {
|
|
|
112
112
|
}
|
|
113
113
|
})().catch(e => {
|
|
114
114
|
lCore.display('[ERROR][CTR][ASYNCTASK]', e);
|
|
115
|
-
lCore.log(this, '[CTR][_asyncTask] ' +
|
|
115
|
+
lCore.log(this, '[CTR][_asyncTask] ' + lText.stringifyJson(e.stack).slice(1, -1), '-error');
|
|
116
116
|
--this._waitInfo.asyncTask.count;
|
|
117
117
|
if (!this._waitInfo.asyncTask.count) {
|
|
118
118
|
this._waitInfo.asyncTask.resolve();
|
|
@@ -184,7 +184,7 @@ export class Ctr {
|
|
|
184
184
|
* @param data
|
|
185
185
|
*/
|
|
186
186
|
async _loadView(path, data = {}) {
|
|
187
|
-
const content = await
|
|
187
|
+
const content = await lFs.getContent(this._config.const.viewPath + path + '.ejs', 'utf8');
|
|
188
188
|
if (!content) {
|
|
189
189
|
return '';
|
|
190
190
|
}
|
|
@@ -485,7 +485,7 @@ export class Ctr {
|
|
|
485
485
|
* @param pwd 密码
|
|
486
486
|
*/
|
|
487
487
|
_getBasicAuth(user, pwd) {
|
|
488
|
-
return 'Basic ' +
|
|
488
|
+
return 'Basic ' + lCrypto.base64Encode(user + ':' + pwd);
|
|
489
489
|
}
|
|
490
490
|
/**
|
|
491
491
|
* --- 根据用户 ua 获取当前用户的设备类型 ---
|
|
@@ -532,7 +532,7 @@ export class Ctr {
|
|
|
532
532
|
// --- 不解析,解析使用 JWT 类解析 ---
|
|
533
533
|
return authArr[1];
|
|
534
534
|
}
|
|
535
|
-
if (!(auth =
|
|
535
|
+
if (!(auth = lCrypto.base64Decode(authArr[1]))) {
|
|
536
536
|
return false;
|
|
537
537
|
}
|
|
538
538
|
authArr = auth.split(':');
|
|
@@ -548,11 +548,11 @@ export class Ctr {
|
|
|
548
548
|
if (loadedData[realPath]) {
|
|
549
549
|
return loadedData[realPath];
|
|
550
550
|
}
|
|
551
|
-
const content = await
|
|
551
|
+
const content = await lFs.getContent(realPath, 'utf8');
|
|
552
552
|
if (!content) {
|
|
553
553
|
return null;
|
|
554
554
|
}
|
|
555
|
-
const json =
|
|
555
|
+
const json = lText.parseJson(content);
|
|
556
556
|
loadedData[realPath] = json;
|
|
557
557
|
return json;
|
|
558
558
|
}
|
|
@@ -562,7 +562,7 @@ export class Ctr {
|
|
|
562
562
|
*/
|
|
563
563
|
_location(location) {
|
|
564
564
|
if (this._res) {
|
|
565
|
-
this._res.setHeader('location',
|
|
565
|
+
this._res.setHeader('location', lText.urlResolve(this._config.const.urlBase, location));
|
|
566
566
|
// this._res.writeHead(302); Kebab 中要在最后设置,否则会报错:ERR_HTTP_HEADERS_SENT
|
|
567
567
|
}
|
|
568
568
|
return false;
|
|
@@ -574,7 +574,7 @@ export class Ctr {
|
|
|
574
574
|
* @param opt name, ttl, ssl, sqlPre
|
|
575
575
|
*/
|
|
576
576
|
async _startSession(link, auth = false, opt = {}) {
|
|
577
|
-
this._sess = new
|
|
577
|
+
this._sess = new lSession.Session();
|
|
578
578
|
await this._sess.init(this, link, auth, opt);
|
|
579
579
|
}
|
|
580
580
|
// --- 本地化 ---
|
|
@@ -632,7 +632,7 @@ export class Ctr {
|
|
|
632
632
|
*/
|
|
633
633
|
_getLocaleJsonString() {
|
|
634
634
|
if (this._localeData[this._locale] !== undefined) {
|
|
635
|
-
return
|
|
635
|
+
return lText.stringifyJson(this._localeData[this._locale]);
|
|
636
636
|
}
|
|
637
637
|
else {
|
|
638
638
|
return '{}';
|