@maiyunnet/kebab 2.0.3 → 2.0.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 +14 -0
- package/index.js +1 -1
- package/lib/buffer.d.ts +25 -0
- package/lib/captcha.d.ts +12 -0
- package/lib/consistent.d.ts +20 -0
- package/lib/core.d.ts +85 -0
- package/lib/crypto.d.ts +47 -0
- package/lib/db.d.ts +88 -0
- package/lib/dns.d.ts +75 -0
- package/lib/fs.d.ts +49 -0
- package/lib/jwt.d.ts +30 -0
- package/lib/kv.d.ts +111 -0
- package/lib/lan.d.ts +10 -0
- package/lib/net/formdata.d.ts +23 -0
- package/lib/net/request.d.ts +23 -0
- package/lib/net/response.d.ts +14 -0
- package/lib/net.d.ts +65 -0
- package/lib/s3.d.ts +35 -0
- package/lib/scan.d.ts +31 -0
- package/lib/session.d.ts +22 -0
- package/lib/sql.d.ts +57 -0
- package/lib/ssh/sftp.d.ts +40 -0
- package/lib/ssh/shell.d.ts +13 -0
- package/lib/ssh.d.ts +24 -0
- package/lib/text.d.ts +40 -0
- package/lib/time.d.ts +22 -0
- package/lib/ws.d.ts +87 -0
- package/lib/zip.d.ts +40 -0
- package/lib/zlib.d.ts +25 -0
- package/main.d.ts +1 -0
- package/package.json +1 -1
- package/sys/child.d.ts +1 -0
- package/sys/cmd.d.ts +1 -0
- package/sys/ctr.d.ts +96 -0
- package/sys/master.d.ts +1 -0
- package/sys/mod.d.ts +205 -0
- package/sys/route.d.ts +31 -0
- package/tsconfig.json +1 -1
- package/www/example/ctr/main.d.ts +4 -0
- package/www/example/ctr/middle.d.ts +6 -0
- package/www/example/ctr/test.d.ts +94 -0
- package/www/example/mod/test.d.ts +20 -0
- package/www/example/mod/testdata.d.ts +9 -0
- package/www/example/ws/mproxy.d.ts +4 -0
- package/www/example/ws/rproxy.d.ts +4 -0
- package/www/example/ws/test.d.ts +7 -0
- package/index.ts +0 -33
- package/lib/buffer.ts +0 -152
- package/lib/captcha.ts +0 -63
- package/lib/consistent.ts +0 -219
- package/lib/core.ts +0 -880
- package/lib/crypto.ts +0 -384
- package/lib/db.ts +0 -719
- package/lib/dns.ts +0 -405
- package/lib/fs.ts +0 -527
- package/lib/jwt.ts +0 -276
- package/lib/kv.ts +0 -1489
- package/lib/lan.ts +0 -87
- package/lib/net/formdata.ts +0 -166
- package/lib/net/request.ts +0 -150
- package/lib/net/response.ts +0 -59
- package/lib/net.ts +0 -662
- package/lib/s3.ts +0 -235
- package/lib/scan.ts +0 -364
- package/lib/session.ts +0 -230
- package/lib/sql.ts +0 -1149
- package/lib/ssh/sftp.ts +0 -508
- package/lib/ssh/shell.ts +0 -123
- package/lib/ssh.ts +0 -191
- package/lib/text.ts +0 -626
- package/lib/time.ts +0 -254
- package/lib/ws.ts +0 -523
- package/lib/zip.ts +0 -447
- package/lib/zlib.ts +0 -350
- package/main.ts +0 -27
- package/sys/child.ts +0 -678
- package/sys/cmd.ts +0 -225
- package/sys/ctr.ts +0 -904
- package/sys/master.ts +0 -355
- package/sys/mod.ts +0 -1871
- package/sys/route.ts +0 -1113
- package/www/example/ctr/main.ts +0 -9
- package/www/example/ctr/middle.ts +0 -26
- package/www/example/ctr/test.ts +0 -3218
- package/www/example/mod/test.ts +0 -47
- package/www/example/mod/testdata.ts +0 -30
- package/www/example/ws/mproxy.ts +0 -16
- package/www/example/ws/rproxy.ts +0 -14
- package/www/example/ws/test.ts +0 -36
package/lib/zlib.ts
DELETED
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
-
* Date: 2019-4-9 16:00:55
|
|
4
|
-
* Last: 2020-03-20 14:45:47, 2022-09-13 13:43:32
|
|
5
|
-
*/
|
|
6
|
-
import * as zlib from 'zlib';
|
|
7
|
-
|
|
8
|
-
/** 某个压缩对象 */
|
|
9
|
-
export interface ICompress {
|
|
10
|
-
readonly type: string;
|
|
11
|
-
readonly compress: zlib.Deflate |
|
|
12
|
-
zlib.Gzip | zlib.BrotliCompress | zlib.Inflate | zlib.Gunzip | zlib.BrotliDecompress;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** 某个压缩后的变量 */
|
|
16
|
-
export interface ICompressBuffer {
|
|
17
|
-
readonly type: string;
|
|
18
|
-
readonly buffer: Buffer;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* --- 创建 Gzip 对象 ---
|
|
23
|
-
* @param options 选项
|
|
24
|
-
*/
|
|
25
|
-
export function createGzip(options: zlib.ZlibOptions = {}): zlib.Gzip {
|
|
26
|
-
if (!options.level) {
|
|
27
|
-
options.level = 7;
|
|
28
|
-
}
|
|
29
|
-
return zlib.createGzip(options);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* --- 创建 Gzip 解压对象 ---
|
|
34
|
-
*/
|
|
35
|
-
export function createGunzip(): zlib.Gunzip {
|
|
36
|
-
return zlib.createGunzip();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* --- 创建 Deflate 对象 ---
|
|
41
|
-
* @param options 选项
|
|
42
|
-
*/
|
|
43
|
-
export function createDeflate(options: zlib.ZlibOptions = {}): zlib.Deflate {
|
|
44
|
-
if (!options.level) {
|
|
45
|
-
options.level = 7;
|
|
46
|
-
}
|
|
47
|
-
return zlib.createDeflate(options);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* --- 创建 Deflate 解压对象 ---
|
|
52
|
-
*/
|
|
53
|
-
export function createInflate(): zlib.Inflate {
|
|
54
|
-
return zlib.createInflate();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* --- 创建 Brotli 压缩对象 ---
|
|
59
|
-
* @param options 选项
|
|
60
|
-
*/
|
|
61
|
-
export function createBrotliCompress(options: zlib.ZlibOptions = {}): zlib.BrotliCompress {
|
|
62
|
-
if (!options.level) {
|
|
63
|
-
options.level = 7;
|
|
64
|
-
}
|
|
65
|
-
return zlib.createBrotliCompress(options);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* --- 创建 Brotli 解压对象 ---
|
|
70
|
-
*/
|
|
71
|
-
export function createBrotliDecompress(): zlib.BrotliDecompress {
|
|
72
|
-
return zlib.createBrotliDecompress();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* --- 根据字符串创建压缩类型 ---
|
|
77
|
-
* @param types 用 , 间隔的字符串,如 gzip,deflate
|
|
78
|
-
* @param options 选项
|
|
79
|
-
*/
|
|
80
|
-
export function createCompress(types: string, options: zlib.ZlibOptions = {}): ICompress | null {
|
|
81
|
-
if (!options.level) {
|
|
82
|
-
options.level = 7;
|
|
83
|
-
}
|
|
84
|
-
const type = getTypeByTypes(types);
|
|
85
|
-
if (!type) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
switch (type) {
|
|
89
|
-
case 'gzip': {
|
|
90
|
-
return {
|
|
91
|
-
'type': 'gzip',
|
|
92
|
-
'compress': zlib.createGzip(options)
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
case 'deflate': {
|
|
96
|
-
return {
|
|
97
|
-
'type': 'deflate',
|
|
98
|
-
'compress': zlib.createDeflate(options)
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
case 'br': {
|
|
102
|
-
return {
|
|
103
|
-
'type': 'br',
|
|
104
|
-
'compress': zlib.createBrotliCompress(options)
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* --- 根据字符串创建解压类型 ---
|
|
113
|
-
* @param types 用 , 间隔的字符串,如 gzip,deflate
|
|
114
|
-
* @param options 选项
|
|
115
|
-
*/
|
|
116
|
-
export function createDecompress(types: string): ICompress | null {
|
|
117
|
-
const type = getTypeByTypes(types);
|
|
118
|
-
if (!type) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
switch (type) {
|
|
122
|
-
case 'gzip': {
|
|
123
|
-
return {
|
|
124
|
-
'type': 'gzip',
|
|
125
|
-
'compress': zlib.createGunzip()
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
case 'deflate': {
|
|
129
|
-
return {
|
|
130
|
-
'type': 'deflate',
|
|
131
|
-
'compress': zlib.createInflate()
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
case 'br': {
|
|
135
|
-
return {
|
|
136
|
-
'type': 'br',
|
|
137
|
-
'compress': zlib.createBrotliDecompress()
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Gzip 压缩一段
|
|
146
|
-
* @param buffer 段
|
|
147
|
-
* @param options 选项
|
|
148
|
-
*/
|
|
149
|
-
export function gzip(buffer: zlib.InputType, options: zlib.ZlibOptions = {}): Promise<Buffer | null> {
|
|
150
|
-
if (!options.level) {
|
|
151
|
-
options.level = 7;
|
|
152
|
-
}
|
|
153
|
-
return new Promise(function(resolve) {
|
|
154
|
-
zlib.gzip(buffer, options, function(error: Error | null, result: Buffer) {
|
|
155
|
-
if (error) {
|
|
156
|
-
resolve(null);
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
resolve(result);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Gzip 解压一段
|
|
167
|
-
* @param buffer 段
|
|
168
|
-
*/
|
|
169
|
-
export function gunzip(buffer: zlib.InputType): Promise<Buffer | null> {
|
|
170
|
-
return new Promise(function(resolve) {
|
|
171
|
-
zlib.gunzip(buffer, function(error: Error | null, result: Buffer) {
|
|
172
|
-
if (error) {
|
|
173
|
-
resolve(null);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
resolve(result);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Deflate 压缩一段
|
|
184
|
-
* @param buffer 段
|
|
185
|
-
* @param options 选项
|
|
186
|
-
*/
|
|
187
|
-
export function deflate(buffer: zlib.InputType, options: zlib.ZlibOptions = {}): Promise<Buffer | null> {
|
|
188
|
-
if (!options.level) {
|
|
189
|
-
options.level = 7;
|
|
190
|
-
}
|
|
191
|
-
return new Promise(function(resolve) {
|
|
192
|
-
zlib.deflate(buffer, options, function(error: Error | null, result: Buffer) {
|
|
193
|
-
if (error) {
|
|
194
|
-
resolve(null);
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
resolve(result);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Deflate 解压一段
|
|
205
|
-
* @param buffer 段
|
|
206
|
-
*/
|
|
207
|
-
export function inflate(buffer: zlib.InputType): Promise<Buffer | null> {
|
|
208
|
-
return new Promise(function(resolve) {
|
|
209
|
-
zlib.inflate(buffer, function(error: Error | null, result: Buffer) {
|
|
210
|
-
if (error) {
|
|
211
|
-
resolve(null);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
resolve(result);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Brotli 压缩一段
|
|
222
|
-
* @param buffer 段
|
|
223
|
-
* @param options 选项
|
|
224
|
-
*/
|
|
225
|
-
export function brotliCompress(buffer: zlib.InputType, options: zlib.ZlibOptions = {}): Promise<Buffer | null> {
|
|
226
|
-
if (!options.level) {
|
|
227
|
-
options.level = 7;
|
|
228
|
-
}
|
|
229
|
-
return new Promise(function(resolve) {
|
|
230
|
-
zlib.brotliCompress(buffer, options, function(error: Error | null, result: Buffer) {
|
|
231
|
-
if (error) {
|
|
232
|
-
resolve(null);
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
resolve(result);
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Brotli 解压一段
|
|
243
|
-
* @param buffer 段
|
|
244
|
-
*/
|
|
245
|
-
export function brotliDecompress(buffer: zlib.InputType): Promise<Buffer | null> {
|
|
246
|
-
return new Promise(function(resolve) {
|
|
247
|
-
zlib.brotliDecompress(buffer, function(error: Error | null, result: Buffer) {
|
|
248
|
-
if (error) {
|
|
249
|
-
resolve(null);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
resolve(result);
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* --- 根据 types 判断用什么加密的段 ---
|
|
260
|
-
* @param types 用,间隔的字符串,如 gzip,deflate
|
|
261
|
-
* @param buffer 段
|
|
262
|
-
* @param options 选项
|
|
263
|
-
*/
|
|
264
|
-
export async function compress(
|
|
265
|
-
types: string,
|
|
266
|
-
buffer: zlib.InputType | null,
|
|
267
|
-
options?: zlib.ZlibOptions
|
|
268
|
-
): Promise<ICompressBuffer | null> {
|
|
269
|
-
if (!buffer) {
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
const type = getTypeByTypes(types);
|
|
273
|
-
if (!type) {
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
let outBuffer: Buffer | null = null;
|
|
277
|
-
switch (type) {
|
|
278
|
-
case 'gzip': {
|
|
279
|
-
outBuffer = await gzip(buffer, options);
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
case 'deflate': {
|
|
283
|
-
outBuffer = await deflate(buffer, options);
|
|
284
|
-
break;
|
|
285
|
-
}
|
|
286
|
-
case 'br': {
|
|
287
|
-
outBuffer = await brotliCompress(buffer, options);
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
if (!outBuffer) {
|
|
292
|
-
return null;
|
|
293
|
-
}
|
|
294
|
-
return {
|
|
295
|
-
'type': type,
|
|
296
|
-
'buffer': outBuffer
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* --- 根据 types 判断用什么解密的段 ---
|
|
302
|
-
* @param types 用,间隔的字符串,如 gzip,deflate
|
|
303
|
-
* @param buffer 段
|
|
304
|
-
*/
|
|
305
|
-
export async function decompress(types: string, buffer: zlib.InputType | null): Promise<ICompressBuffer | null> {
|
|
306
|
-
if (!buffer) {
|
|
307
|
-
return null;
|
|
308
|
-
}
|
|
309
|
-
const type = getTypeByTypes(types);
|
|
310
|
-
if (!type) {
|
|
311
|
-
return null;
|
|
312
|
-
}
|
|
313
|
-
let outBuffer: Buffer | null = null;
|
|
314
|
-
switch (type) {
|
|
315
|
-
case 'gzip': {
|
|
316
|
-
outBuffer = await gunzip(buffer);
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
case 'deflate': {
|
|
320
|
-
outBuffer = await inflate(buffer);
|
|
321
|
-
break;
|
|
322
|
-
}
|
|
323
|
-
case 'br': {
|
|
324
|
-
outBuffer = await brotliDecompress(buffer);
|
|
325
|
-
break;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
if (!outBuffer) {
|
|
329
|
-
return null;
|
|
330
|
-
}
|
|
331
|
-
return {
|
|
332
|
-
'type': type,
|
|
333
|
-
'buffer': outBuffer
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* --- 根据 types 字符串获取优先 type
|
|
339
|
-
* @param types types 字符串
|
|
340
|
-
*/
|
|
341
|
-
function getTypeByTypes(types: string): string| null {
|
|
342
|
-
const typesArray = types.split(',');
|
|
343
|
-
for (let type of typesArray) {
|
|
344
|
-
type = type.trim().toLowerCase();
|
|
345
|
-
if (['gzip', 'deflate', 'br'].includes(type)) {
|
|
346
|
-
return type;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
return null;
|
|
350
|
-
}
|
package/main.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-floating-promises */
|
|
2
|
-
/**
|
|
3
|
-
* Project: Kebab, User: JianSuoQiYue
|
|
4
|
-
* Date: 2019-3-29 18:55:35
|
|
5
|
-
* Last: 2020-3-6 22:19:37, 2022-3-30 01:01:22, 2022-9-27 16:11:40, 2025-6-13 12:56:18
|
|
6
|
-
*/
|
|
7
|
-
// git config core.ignorecase false
|
|
8
|
-
|
|
9
|
-
import cluster from 'cluster';
|
|
10
|
-
// --- 第三方 ---
|
|
11
|
-
import 'ts-alias-loader';
|
|
12
|
-
|
|
13
|
-
// --- 初始化 ---
|
|
14
|
-
// --- 一定要分别隔离加载 Master 和 Child 代码,防止执行串了 ---
|
|
15
|
-
if (cluster.isPrimary) {
|
|
16
|
-
if (process.argv.length > 2) {
|
|
17
|
-
// --- 传入的命令方式启动,则执行 RPC 相关命令 ---
|
|
18
|
-
import('./sys/cmd');
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
// --- 正常启动 ---
|
|
22
|
-
import('./sys/master');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
import('./sys/child');
|
|
27
|
-
}
|