@maiyunnet/kebab 2.0.7 → 2.0.9
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 +11 -1
- package/index.js +13 -1
- package/lib/buffer.d.ts +25 -0
- package/lib/buffer.js +30 -5
- package/lib/captcha.d.ts +15 -0
- package/lib/captcha.js +20 -0
- package/lib/consistent.d.ts +51 -0
- package/lib/consistent.js +59 -0
- package/lib/core.d.ts +134 -0
- package/lib/core.js +176 -0
- package/lib/crypto.d.ts +75 -6
- package/lib/crypto.js +206 -38
- package/lib/db.d.ts +104 -0
- package/lib/db.js +126 -0
- package/lib/dns.d.ts +51 -0
- package/lib/dns.js +54 -2
- package/lib/fs.d.ts +100 -0
- package/lib/fs.js +118 -0
- package/lib/jwt.d.ts +43 -0
- package/lib/jwt.js +45 -0
- package/lib/kv.d.ts +362 -0
- package/lib/kv.js +377 -0
- package/lib/lan.d.ts +6 -0
- package/lib/lan.js +7 -0
- package/lib/net/formdata.d.ts +38 -0
- package/lib/net/formdata.js +43 -0
- package/lib/net/request.d.ts +62 -0
- package/lib/net/request.js +57 -0
- package/lib/net/response.d.ts +21 -0
- package/lib/net/response.js +16 -0
- package/lib/net.d.ts +86 -0
- package/lib/net.js +140 -0
- package/lib/s3.d.ts +52 -0
- package/lib/s3.js +51 -0
- package/lib/scan.d.ts +52 -0
- package/lib/scan.js +84 -0
- package/lib/session.d.ts +31 -0
- package/lib/session.js +52 -1
- package/lib/sql.d.ts +176 -0
- package/lib/sql.js +287 -2
- package/lib/ssh/sftp.d.ts +106 -0
- package/lib/ssh/sftp.js +106 -0
- package/lib/ssh/shell.d.ts +37 -0
- package/lib/ssh/shell.js +31 -0
- package/lib/ssh.d.ts +32 -0
- package/lib/ssh.js +32 -0
- package/lib/text.d.ts +131 -0
- package/lib/text.js +188 -0
- package/lib/time.d.ts +53 -0
- package/lib/time.js +55 -0
- package/lib/ws.d.ts +68 -0
- package/lib/ws.js +74 -0
- package/lib/zip.d.ts +53 -0
- package/lib/zip.js +73 -0
- package/lib/zlib.d.ts +76 -0
- package/lib/zlib.js +78 -0
- package/main.d.ts +5 -0
- package/main.js +12 -0
- package/package.json +3 -2
- package/sys/child.js +104 -0
- package/sys/cmd.js +28 -0
- package/sys/ctr.d.ts +166 -0
- package/sys/ctr.js +177 -0
- package/sys/master.js +63 -0
- package/sys/mod.d.ts +266 -0
- package/sys/mod.js +335 -0
- package/sys/route.d.ts +34 -0
- package/sys/route.js +164 -0
- package/www/example/ctr/test.d.ts +3 -0
- package/www/example/ctr/test.js +63 -1
- package/www/example/mod/test.js +14 -0
- package/www/example/mod/testdata.js +9 -0
- package/www/example/ws/test.js +1 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/details.md +0 -82
- package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +0 -15
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +0 -2
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +0 -19
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +0 -22
- package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +0 -69
- package/.VSCodeCounter/2025-02-14_14-46-44/results.json +0 -1
- package/.VSCodeCounter/2025-02-14_14-46-44/results.md +0 -48
- package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +0 -118
- package/.vscode/tasks.json +0 -15
package/lib/lan.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --- 获取当前网卡的 IP、MAC 信息 ---
|
|
3
|
+
*/
|
|
1
4
|
export declare function card(): Promise<Array<{
|
|
2
5
|
'name': string;
|
|
3
6
|
'mac': string;
|
|
4
7
|
'iPv4': string;
|
|
5
8
|
'iPv6': string;
|
|
6
9
|
}>>;
|
|
10
|
+
/**
|
|
11
|
+
* --- 扫描发生关联的局域网 IP ---
|
|
12
|
+
*/
|
|
7
13
|
export declare function scan(): Promise<Array<{
|
|
8
14
|
'mac': string;
|
|
9
15
|
'iPv4': string;
|
package/lib/lan.js
CHANGED
|
@@ -37,6 +37,9 @@ exports.card = card;
|
|
|
37
37
|
exports.scan = scan;
|
|
38
38
|
const os = __importStar(require("os"));
|
|
39
39
|
const lCore = __importStar(require("../lib/core"));
|
|
40
|
+
/**
|
|
41
|
+
* --- 获取当前网卡的 IP、MAC 信息 ---
|
|
42
|
+
*/
|
|
40
43
|
async function card() {
|
|
41
44
|
const result = [];
|
|
42
45
|
let i = 0;
|
|
@@ -48,6 +51,7 @@ async function card() {
|
|
|
48
51
|
continue;
|
|
49
52
|
}
|
|
50
53
|
for (const name in nifs) {
|
|
54
|
+
/** --- 当前网卡 --- */
|
|
51
55
|
const card = nifs[name];
|
|
52
56
|
if (!card) {
|
|
53
57
|
continue;
|
|
@@ -78,6 +82,9 @@ async function card() {
|
|
|
78
82
|
}
|
|
79
83
|
return result;
|
|
80
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* --- 扫描发生关联的局域网 IP ---
|
|
87
|
+
*/
|
|
81
88
|
async function scan() {
|
|
82
89
|
const result = [];
|
|
83
90
|
const res = await lCore.exec('arp -a');
|
package/lib/net/formdata.d.ts
CHANGED
|
@@ -1,23 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
+
* Date: 2020-04-07 23:45:03
|
|
4
|
+
* Last: 2020-04-07 23:45:07, 2022-09-10 01:35:25
|
|
5
|
+
*/
|
|
1
6
|
import * as stream from 'stream';
|
|
7
|
+
/** --- Item 对象 --- */
|
|
2
8
|
export interface IItem {
|
|
9
|
+
/** --- key 键 --- */
|
|
3
10
|
'key': string;
|
|
4
11
|
'isFile': boolean;
|
|
5
12
|
'isString': boolean;
|
|
13
|
+
/** --- 值或者文件名 --- */
|
|
6
14
|
'value': string;
|
|
7
15
|
'path': string;
|
|
8
16
|
}
|
|
9
17
|
export declare class FormData extends stream.Readable {
|
|
18
|
+
/** --- read 调用次数 --- */
|
|
10
19
|
private _num;
|
|
20
|
+
/** --- 要编译的数据 --- */
|
|
11
21
|
private readonly _data;
|
|
22
|
+
/** --- 分隔符 --- */
|
|
12
23
|
private readonly _boundary;
|
|
24
|
+
/** --- 正在读取文件吗 --- */
|
|
13
25
|
private _fileReading;
|
|
26
|
+
/** --- 是否已经结束 --- */
|
|
14
27
|
private _close;
|
|
28
|
+
/** --- 总字节长度 --- */
|
|
15
29
|
private _length;
|
|
30
|
+
/** --- 已发送字节长度 --- */
|
|
16
31
|
private _sent;
|
|
32
|
+
/**
|
|
33
|
+
* --- 添加字符串 ---
|
|
34
|
+
* @param key 键
|
|
35
|
+
* @param val 值
|
|
36
|
+
*/
|
|
17
37
|
putString(key: string, val: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* --- 添加文件 ---
|
|
40
|
+
* @param key 键
|
|
41
|
+
* @param path 路径
|
|
42
|
+
* @param fname 可选,文件名
|
|
43
|
+
*/
|
|
18
44
|
putFile(key: string, path: string, fname?: string): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* --- 获取 boundary ---
|
|
47
|
+
*/
|
|
19
48
|
getBoundary(): string;
|
|
49
|
+
/**
|
|
50
|
+
* --- 获取总字节长度 ---
|
|
51
|
+
*/
|
|
20
52
|
getLength(): number;
|
|
53
|
+
/**
|
|
54
|
+
* --- 获取已发送的字节长度 ---
|
|
55
|
+
*/
|
|
21
56
|
getSent(): number;
|
|
57
|
+
/**
|
|
58
|
+
* --- 间隔读取(on data 或 pipe 触发)---
|
|
59
|
+
*/
|
|
22
60
|
_read(): void;
|
|
23
61
|
}
|
package/lib/net/formdata.js
CHANGED
|
@@ -34,6 +34,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.FormData = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
39
|
+
* Date: 2020-04-07 23:45:03
|
|
40
|
+
* Last: 2020-04-07 23:45:07, 2022-09-10 01:35:25
|
|
41
|
+
*/
|
|
37
42
|
const stream = __importStar(require("stream"));
|
|
38
43
|
const mime = __importStar(require("@litert/mime"));
|
|
39
44
|
const core = __importStar(require("../../lib/core"));
|
|
@@ -41,14 +46,26 @@ const fs = __importStar(require("../../lib/fs"));
|
|
|
41
46
|
class FormData extends stream.Readable {
|
|
42
47
|
constructor() {
|
|
43
48
|
super(...arguments);
|
|
49
|
+
/** --- read 调用次数 --- */
|
|
44
50
|
this._num = 0;
|
|
51
|
+
/** --- 要编译的数据 --- */
|
|
45
52
|
this._data = [];
|
|
53
|
+
/** --- 分隔符 --- */
|
|
46
54
|
this._boundary = '----Kebab' + core.random(29, core.RANDOM_LUN);
|
|
55
|
+
/** --- 正在读取文件吗 --- */
|
|
47
56
|
this._fileReading = false;
|
|
57
|
+
/** --- 是否已经结束 --- */
|
|
48
58
|
this._close = false;
|
|
59
|
+
/** --- 总字节长度 --- */
|
|
49
60
|
this._length = 4 + this._boundary.length;
|
|
61
|
+
/** --- 已发送字节长度 --- */
|
|
50
62
|
this._sent = 0;
|
|
51
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* --- 添加字符串 ---
|
|
66
|
+
* @param key 键
|
|
67
|
+
* @param val 值
|
|
68
|
+
*/
|
|
52
69
|
putString(key, val) {
|
|
53
70
|
this._data.push({
|
|
54
71
|
'key': key,
|
|
@@ -59,6 +76,12 @@ class FormData extends stream.Readable {
|
|
|
59
76
|
});
|
|
60
77
|
this._length += this._boundary.length + 49 + Buffer.byteLength(key) + Buffer.byteLength(val);
|
|
61
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* --- 添加文件 ---
|
|
81
|
+
* @param key 键
|
|
82
|
+
* @param path 路径
|
|
83
|
+
* @param fname 可选,文件名
|
|
84
|
+
*/
|
|
62
85
|
async putFile(key, path, fname) {
|
|
63
86
|
path = path.replace(/\\/g, '/');
|
|
64
87
|
const stat = await fs.stats(path);
|
|
@@ -81,23 +104,40 @@ class FormData extends stream.Readable {
|
|
|
81
104
|
mime.getMime(fname).length + stat.size + 2;
|
|
82
105
|
return true;
|
|
83
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* --- 获取 boundary ---
|
|
109
|
+
*/
|
|
84
110
|
getBoundary() {
|
|
85
111
|
return this._boundary;
|
|
86
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* --- 获取总字节长度 ---
|
|
115
|
+
*/
|
|
87
116
|
getLength() {
|
|
88
117
|
return this._length;
|
|
89
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* --- 获取已发送的字节长度 ---
|
|
121
|
+
*/
|
|
90
122
|
getSent() {
|
|
91
123
|
return this._sent;
|
|
92
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* --- 间隔读取(on data 或 pipe 触发)---
|
|
127
|
+
*/
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
93
129
|
_read() {
|
|
94
130
|
if (this._close) {
|
|
131
|
+
// --- 结束了 ---
|
|
95
132
|
this.push(null);
|
|
96
133
|
return;
|
|
97
134
|
}
|
|
135
|
+
// --- 文件读取中 ---
|
|
98
136
|
if (this._fileReading) {
|
|
137
|
+
// --- 等待下面 fileReadable 的 on data 或 end 事件 ---
|
|
99
138
|
return;
|
|
100
139
|
}
|
|
140
|
+
// --- 获取当前 item ---
|
|
101
141
|
const item = this._data[this._num];
|
|
102
142
|
if (!item) {
|
|
103
143
|
this._close = true;
|
|
@@ -107,14 +147,17 @@ class FormData extends stream.Readable {
|
|
|
107
147
|
return;
|
|
108
148
|
}
|
|
109
149
|
if (item.isString) {
|
|
150
|
+
// --- 字段 ---
|
|
110
151
|
const push = `--${this._boundary}\r\nContent-Disposition: form-data; name="${item.key}"\r\n\r\n${item.value}\r\n`;
|
|
111
152
|
this._sent += Buffer.byteLength(push);
|
|
112
153
|
this.push(push);
|
|
113
154
|
}
|
|
114
155
|
else {
|
|
156
|
+
// --- 文件 ---
|
|
115
157
|
const push = `--${this._boundary}\r\nContent-Disposition: form-data; name="${item.key}"; filename="${item.value}"\r\nContent-Type: ${mime.getMime(item.value)}\r\n\r\n`;
|
|
116
158
|
this._sent += Buffer.byteLength(push);
|
|
117
159
|
this.push(push);
|
|
160
|
+
// --- 创建流 ---
|
|
118
161
|
this._fileReading = true;
|
|
119
162
|
const fileReadable = fs.createReadStream(item.path);
|
|
120
163
|
fileReadable.on('data', (chunk) => {
|
package/lib/net/request.d.ts
CHANGED
|
@@ -1,23 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
+
* Date: 2020-4-9 20:02:39
|
|
4
|
+
* Last: 2020-4-9 20:47:58, 2022-09-10 01:35:34
|
|
5
|
+
*/
|
|
1
6
|
import * as stream from 'stream';
|
|
2
7
|
import * as response from './response';
|
|
3
8
|
import * as types from '../../types';
|
|
4
9
|
export declare class Request {
|
|
10
|
+
/** --- get 或 post 的数据 --- */
|
|
5
11
|
private _data;
|
|
12
|
+
/** --- 访问的 URL --- */
|
|
6
13
|
private readonly _url;
|
|
14
|
+
/** --- 要传递的参数 --- */
|
|
7
15
|
private _opt;
|
|
8
16
|
constructor(url: string);
|
|
17
|
+
/**
|
|
18
|
+
* --- 设置 get 或 post 的数据 ---
|
|
19
|
+
* @param data 数据
|
|
20
|
+
*/
|
|
9
21
|
data(data: Record<string, any> | Buffer | string | stream.Readable): this;
|
|
22
|
+
/**
|
|
23
|
+
* --- 设置 get 或 post 请求 ---
|
|
24
|
+
* @param method
|
|
25
|
+
*/
|
|
10
26
|
method(method: 'GET' | 'POST'): this;
|
|
27
|
+
/**
|
|
28
|
+
* --- method get 方法别名 ---
|
|
29
|
+
*/
|
|
11
30
|
get(): this;
|
|
31
|
+
/**
|
|
32
|
+
* --- method post 方法别名 ---
|
|
33
|
+
*/
|
|
12
34
|
post(): this;
|
|
35
|
+
/**
|
|
36
|
+
* --- 设置提交模式,json 还是普通 form ---
|
|
37
|
+
* @param type
|
|
38
|
+
*/
|
|
13
39
|
type(type: 'form' | 'json'): this;
|
|
40
|
+
/**
|
|
41
|
+
* --- type json 方法别名 ---
|
|
42
|
+
*/
|
|
14
43
|
json(): this;
|
|
44
|
+
/**
|
|
45
|
+
* --- 设置请求有效期 ---
|
|
46
|
+
* @param timeout 秒
|
|
47
|
+
*/
|
|
15
48
|
timeout(timeout: number): this;
|
|
49
|
+
/**
|
|
50
|
+
* --- 设置是否跟随请求方的 location,留空为跟随,不设置为不跟随 ---
|
|
51
|
+
* @param follow
|
|
52
|
+
*/
|
|
16
53
|
follow(follow?: number): this;
|
|
54
|
+
/**
|
|
55
|
+
* --- 设置域名 -> ip的对应键值,就像电脑里的 hosts 一样 ---
|
|
56
|
+
* @param hosts
|
|
57
|
+
*/
|
|
17
58
|
hosts(hosts: Record<string, string>): this;
|
|
59
|
+
/**
|
|
60
|
+
* --- 设置后将直接保存到本地文件,不会返回,save 为本地实体路径 ---
|
|
61
|
+
* @param save
|
|
62
|
+
*/
|
|
18
63
|
save(save: string): this;
|
|
64
|
+
/**
|
|
65
|
+
* --- 设置使用的本地网卡 IP ---
|
|
66
|
+
* @param addr
|
|
67
|
+
*/
|
|
19
68
|
local(addr: string): this;
|
|
69
|
+
/**
|
|
70
|
+
* --- 批量设置提交的 headers ---
|
|
71
|
+
* @param headers
|
|
72
|
+
*/
|
|
20
73
|
headers(headers: types.THttpHeaders): this;
|
|
74
|
+
/**
|
|
75
|
+
* --- 设置单条 header ---
|
|
76
|
+
* @param name
|
|
77
|
+
* @param val
|
|
78
|
+
*/
|
|
21
79
|
setHeader(name: string, val: string): this;
|
|
80
|
+
/**
|
|
81
|
+
* --- 发起请求 ---
|
|
82
|
+
* @param cookie
|
|
83
|
+
*/
|
|
22
84
|
request(cookie?: Record<string, types.ICookie>): Promise<response.Response>;
|
|
23
85
|
}
|
package/lib/net/request.js
CHANGED
|
@@ -37,56 +37,109 @@ exports.Request = void 0;
|
|
|
37
37
|
const net = __importStar(require("../../lib/net"));
|
|
38
38
|
class Request {
|
|
39
39
|
constructor(url) {
|
|
40
|
+
/** --- get 或 post 的数据 --- */
|
|
40
41
|
this._data = undefined;
|
|
42
|
+
/** --- 访问的 URL --- */
|
|
41
43
|
this._url = '';
|
|
44
|
+
/** --- 要传递的参数 --- */
|
|
42
45
|
this._opt = {};
|
|
43
46
|
this._url = url;
|
|
44
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* --- 设置 get 或 post 的数据 ---
|
|
50
|
+
* @param data 数据
|
|
51
|
+
*/
|
|
45
52
|
data(data) {
|
|
46
53
|
this._data = data;
|
|
47
54
|
return this;
|
|
48
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* --- 设置 get 或 post 请求 ---
|
|
58
|
+
* @param method
|
|
59
|
+
*/
|
|
49
60
|
method(method) {
|
|
50
61
|
this._opt['method'] = method;
|
|
51
62
|
return this;
|
|
52
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* --- method get 方法别名 ---
|
|
66
|
+
*/
|
|
53
67
|
get() {
|
|
54
68
|
return this.method('GET');
|
|
55
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* --- method post 方法别名 ---
|
|
72
|
+
*/
|
|
56
73
|
post() {
|
|
57
74
|
return this.method('POST');
|
|
58
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* --- 设置提交模式,json 还是普通 form ---
|
|
78
|
+
* @param type
|
|
79
|
+
*/
|
|
59
80
|
type(type) {
|
|
60
81
|
this._opt['type'] = type;
|
|
61
82
|
return this;
|
|
62
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* --- type json 方法别名 ---
|
|
86
|
+
*/
|
|
63
87
|
json() {
|
|
64
88
|
return this.type('json');
|
|
65
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* --- 设置请求有效期 ---
|
|
92
|
+
* @param timeout 秒
|
|
93
|
+
*/
|
|
66
94
|
timeout(timeout) {
|
|
67
95
|
this._opt['timeout'] = timeout;
|
|
68
96
|
return this;
|
|
69
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* --- 设置是否跟随请求方的 location,留空为跟随,不设置为不跟随 ---
|
|
100
|
+
* @param follow
|
|
101
|
+
*/
|
|
70
102
|
follow(follow = 5) {
|
|
71
103
|
this._opt['follow'] = follow;
|
|
72
104
|
return this;
|
|
73
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* --- 设置域名 -> ip的对应键值,就像电脑里的 hosts 一样 ---
|
|
108
|
+
* @param hosts
|
|
109
|
+
*/
|
|
74
110
|
hosts(hosts) {
|
|
75
111
|
this._opt['hosts'] = hosts;
|
|
76
112
|
return this;
|
|
77
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* --- 设置后将直接保存到本地文件,不会返回,save 为本地实体路径 ---
|
|
116
|
+
* @param save
|
|
117
|
+
*/
|
|
78
118
|
save(save) {
|
|
79
119
|
this._opt['save'] = save;
|
|
80
120
|
return this;
|
|
81
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* --- 设置使用的本地网卡 IP ---
|
|
124
|
+
* @param addr
|
|
125
|
+
*/
|
|
82
126
|
local(addr) {
|
|
83
127
|
this._opt['local'] = addr;
|
|
84
128
|
return this;
|
|
85
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* --- 批量设置提交的 headers ---
|
|
132
|
+
* @param headers
|
|
133
|
+
*/
|
|
86
134
|
headers(headers) {
|
|
87
135
|
this._opt['headers'] = headers;
|
|
88
136
|
return this;
|
|
89
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* --- 设置单条 header ---
|
|
140
|
+
* @param name
|
|
141
|
+
* @param val
|
|
142
|
+
*/
|
|
90
143
|
setHeader(name, val) {
|
|
91
144
|
if (!this._opt['headers']) {
|
|
92
145
|
this._opt['headers'] = {};
|
|
@@ -94,6 +147,10 @@ class Request {
|
|
|
94
147
|
this._opt['headers'][name] = val;
|
|
95
148
|
return this;
|
|
96
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* --- 发起请求 ---
|
|
152
|
+
* @param cookie
|
|
153
|
+
*/
|
|
97
154
|
async request(cookie) {
|
|
98
155
|
this._opt.cookie = cookie;
|
|
99
156
|
return net.request(this._url, this._data, this._opt);
|
package/lib/net/response.d.ts
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
+
* Date: 2020-4-9 15:33:06
|
|
4
|
+
* Last: 2020-4-12 11:12:03, 2022-09-10 12:43:23, 2022-12-25 15:12:57, 2023-9-26 14:20:41
|
|
5
|
+
*/
|
|
1
6
|
import * as hc from '@litert/http-client';
|
|
2
7
|
import * as nStream from 'stream';
|
|
3
8
|
import * as types from '../../types';
|
|
4
9
|
export declare class Response {
|
|
10
|
+
/** --- httpClient 请求对象 --- */
|
|
5
11
|
private readonly _req;
|
|
12
|
+
/** --- 返回的 headers --- */
|
|
6
13
|
headers: types.THttpHeaders | null;
|
|
7
14
|
error: Error | null;
|
|
15
|
+
/** --- 用户自定义的 content 内容 --- */
|
|
8
16
|
private _content;
|
|
9
17
|
constructor(req: hc.IResponse | null);
|
|
18
|
+
/**
|
|
19
|
+
* --- 读取所有内容到内存 ---
|
|
20
|
+
*/
|
|
10
21
|
getContent(): Promise<Buffer | null>;
|
|
22
|
+
/**
|
|
23
|
+
* --- 用户自定义的 content 内容 ---
|
|
24
|
+
* @param v 内容值
|
|
25
|
+
*/
|
|
11
26
|
setContent(v: string | Buffer): void;
|
|
27
|
+
/**
|
|
28
|
+
* --- 获取响应读取流对象 ---
|
|
29
|
+
*/
|
|
12
30
|
getStream(): nStream.Readable;
|
|
31
|
+
/**
|
|
32
|
+
* --- 获取原生响应读取流对象 ---
|
|
33
|
+
*/
|
|
13
34
|
getRawStream(): nStream.Readable;
|
|
14
35
|
}
|
package/lib/net/response.js
CHANGED
|
@@ -3,24 +3,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Response = void 0;
|
|
4
4
|
class Response {
|
|
5
5
|
constructor(req) {
|
|
6
|
+
/** --- httpClient 请求对象 --- */
|
|
6
7
|
this._req = null;
|
|
8
|
+
/** --- 返回的 headers --- */
|
|
7
9
|
this.headers = null;
|
|
8
10
|
this.error = null;
|
|
11
|
+
/** --- 用户自定义的 content 内容 --- */
|
|
9
12
|
this._content = null;
|
|
10
13
|
this._req = req;
|
|
11
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* --- 读取所有内容到内存 ---
|
|
17
|
+
*/
|
|
12
18
|
async getContent() {
|
|
13
19
|
if (this._content) {
|
|
14
20
|
return this._content;
|
|
15
21
|
}
|
|
16
22
|
return this._req ? this._req.getBuffer() : null;
|
|
17
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* --- 用户自定义的 content 内容 ---
|
|
26
|
+
* @param v 内容值
|
|
27
|
+
*/
|
|
18
28
|
setContent(v) {
|
|
19
29
|
this._content = typeof v === 'string' ? Buffer.from(v) : v;
|
|
20
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* --- 获取响应读取流对象 ---
|
|
33
|
+
*/
|
|
21
34
|
getStream() {
|
|
22
35
|
return this._req.getStream();
|
|
23
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* --- 获取原生响应读取流对象 ---
|
|
39
|
+
*/
|
|
24
40
|
getRawStream() {
|
|
25
41
|
return this._req.getRawStream();
|
|
26
42
|
}
|
package/lib/net.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
+
* Date: 2019-5-15 22:47
|
|
4
|
+
* CA: https://curl.haxx.se/ca/cacert.pem
|
|
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
|
|
6
|
+
*/
|
|
1
7
|
import * as stream from 'stream';
|
|
2
8
|
import * as http from 'http';
|
|
3
9
|
import * as http2 from 'http2';
|
|
@@ -6,60 +12,140 @@ import * as types from '../types';
|
|
|
6
12
|
import * as fd from './net/formdata';
|
|
7
13
|
import * as lRequest from './net/request';
|
|
8
14
|
import * as response from './net/response';
|
|
15
|
+
/** --- 请求的传入参数选项 --- */
|
|
9
16
|
export interface IRequestOptions {
|
|
10
17
|
'method'?: 'GET' | 'POST' | 'OPTIONS';
|
|
11
18
|
'type'?: 'form' | 'json';
|
|
19
|
+
/** --- 秒数 --- */
|
|
12
20
|
'timeout'?: number;
|
|
13
21
|
'follow'?: number;
|
|
14
22
|
'hosts'?: Record<string, string>;
|
|
15
23
|
'save'?: string;
|
|
16
24
|
'local'?: string;
|
|
17
25
|
'headers'?: types.THttpHeaders;
|
|
26
|
+
/** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
|
|
18
27
|
'mproxy'?: {
|
|
19
28
|
'url': string;
|
|
20
29
|
'auth': string;
|
|
21
30
|
'data'?: any;
|
|
22
31
|
};
|
|
32
|
+
/** --- 默认为 default --- */
|
|
23
33
|
'reuse'?: string;
|
|
34
|
+
/** --- cookie 托管对象 --- */
|
|
24
35
|
'cookie'?: Record<string, types.ICookie>;
|
|
25
36
|
}
|
|
37
|
+
/** --- 正向代理请求的传入参数选项 --- */
|
|
26
38
|
export interface IMproxyOptions {
|
|
39
|
+
/** --- 秒数 --- */
|
|
27
40
|
'timeout'?: number;
|
|
28
41
|
'follow'?: number;
|
|
29
42
|
'hosts'?: Record<string, string>;
|
|
30
43
|
'local'?: string;
|
|
31
44
|
'headers'?: types.THttpHeaders;
|
|
45
|
+
/** --- 默认为 default --- */
|
|
32
46
|
'reuse'?: string;
|
|
33
47
|
}
|
|
48
|
+
/** --- 反向代理请求的传入参数选项 --- */
|
|
34
49
|
export interface IRproxyOptions {
|
|
50
|
+
/** --- 秒数 --- */
|
|
35
51
|
'timeout'?: number;
|
|
36
52
|
'follow'?: number;
|
|
37
53
|
'hosts'?: Record<string, string>;
|
|
38
54
|
'local'?: string;
|
|
39
55
|
'headers'?: types.THttpHeaders;
|
|
56
|
+
/** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
|
|
40
57
|
'mproxy'?: {
|
|
41
58
|
'url': string;
|
|
42
59
|
'auth': string;
|
|
43
60
|
'data'?: any;
|
|
44
61
|
};
|
|
62
|
+
/** --- 默认为 default --- */
|
|
45
63
|
'reuse'?: string;
|
|
46
64
|
}
|
|
65
|
+
/** --- 获取 CA 证书 --- */
|
|
47
66
|
export declare function getCa(): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* --- 创建一个请求对象 ---
|
|
69
|
+
* @param u
|
|
70
|
+
*/
|
|
48
71
|
export declare function open(u: string): lRequest.Request;
|
|
72
|
+
/**
|
|
73
|
+
* --- 发起一个 get 请求 ---
|
|
74
|
+
* @param u 请求的 URL
|
|
75
|
+
* @param opt 参数
|
|
76
|
+
*/
|
|
49
77
|
export declare function get(u: string, opt?: IRequestOptions): Promise<response.Response>;
|
|
78
|
+
/**
|
|
79
|
+
* --- 发起一个 post 请求 ---
|
|
80
|
+
* @param u 请求的 URL
|
|
81
|
+
* @param data 要发送的数据
|
|
82
|
+
* @param opt 参数
|
|
83
|
+
*/
|
|
50
84
|
export declare function post(u: string, data: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<response.Response>;
|
|
85
|
+
/**
|
|
86
|
+
* --- 发起 JSON 请求 ---
|
|
87
|
+
* @param u
|
|
88
|
+
* @param data
|
|
89
|
+
* @param opt
|
|
90
|
+
*/
|
|
51
91
|
export declare function postJson(u: string, data: types.Json[] | Record<string, types.Json>, opt?: IRequestOptions): Promise<response.Response>;
|
|
92
|
+
/**
|
|
93
|
+
* --- 发起一个请求 ---
|
|
94
|
+
* @param opt 配置项
|
|
95
|
+
*/
|
|
52
96
|
export declare function request(u: string, data?: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<response.Response>;
|
|
97
|
+
/**
|
|
98
|
+
* --- 对 cookie 对象进行操作 ---
|
|
99
|
+
* @param cookie 要操作的对象
|
|
100
|
+
* @param name 名
|
|
101
|
+
* @param value 值
|
|
102
|
+
* @param domain 应用网址,如 .xxx.com
|
|
103
|
+
* @param opt 选项 ttl, path, ssl, httponly
|
|
104
|
+
*/
|
|
53
105
|
export declare function setCookie(cookie: Record<string, types.ICookie>, name: string, value: string, domain: string, opt?: {
|
|
54
106
|
'ttl'?: number;
|
|
55
107
|
'path'?: string;
|
|
56
108
|
'ssl'?: boolean;
|
|
57
109
|
'httponly'?: boolean;
|
|
58
110
|
}): void;
|
|
111
|
+
/**
|
|
112
|
+
* --- 对象转换为 Cookie 拼接字符串(会自动筛掉不能发送的 cookie) ---
|
|
113
|
+
* @param cookie cookie 对象
|
|
114
|
+
* @param uri 请求的 URI 对象
|
|
115
|
+
*/
|
|
59
116
|
export declare function buildCookieQuery(cookie: Record<string, types.ICookie>, uri: types.IUrlParse): string;
|
|
117
|
+
/**
|
|
118
|
+
* --- 模拟重启浏览器后的状态 ---
|
|
119
|
+
* @param cookie cookie 对象
|
|
120
|
+
*/
|
|
60
121
|
export declare function resetCookieSession(cookie: Record<string, types.ICookie>): void;
|
|
122
|
+
/**
|
|
123
|
+
* --- 创建 FormData 对象, Mutton: false, Kebab: true ---
|
|
124
|
+
*/
|
|
61
125
|
export declare function getFormData(): fd.FormData;
|
|
126
|
+
/**
|
|
127
|
+
* --- 剔除不代理的 header ---
|
|
128
|
+
* @param headers 剔除前的 header
|
|
129
|
+
* @param res 直接设置头部而不返回,可置空
|
|
130
|
+
*/
|
|
62
131
|
export declare function filterProxyHeaders(headers: http.IncomingHttpHeaders | http2.IncomingHttpHeaders | types.THttpHeaders, res?: http2.Http2ServerResponse | http.ServerResponse): Record<string, string | string[]>;
|
|
132
|
+
/**
|
|
133
|
+
* --- 正向 mproxy 代理,读取 get 的 url 为实际请求地址 ---
|
|
134
|
+
* --- get: url, auth ---
|
|
135
|
+
* @param ctr 当前控制器
|
|
136
|
+
* @param auth 校验字符串,读取 get 的 auth 和本参数做比对
|
|
137
|
+
* @param opt 参数
|
|
138
|
+
*/
|
|
63
139
|
export declare function mproxy(ctr: ctr.Ctr, auth: string, opt?: IMproxyOptions): Promise<number>;
|
|
140
|
+
/**
|
|
141
|
+
* --- 获取 mproxy 的附加数据 ---
|
|
142
|
+
* @param ctr 当前控制器
|
|
143
|
+
*/
|
|
64
144
|
export declare function mproxyData(ctr: ctr.Ctr): any;
|
|
145
|
+
/**
|
|
146
|
+
* --- 反向代理,将本服务器的某个路由反代到其他网址 ---
|
|
147
|
+
* @param ctr 当前控制器
|
|
148
|
+
* @param route 要反代的路由
|
|
149
|
+
* @param opt 参数
|
|
150
|
+
*/
|
|
65
151
|
export declare function rproxy(ctr: ctr.Ctr, route: Record<string, string>, opt?: IRproxyOptions): Promise<boolean>;
|