@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.
Files changed (89) hide show
  1. package/index.d.ts +14 -0
  2. package/index.js +1 -1
  3. package/lib/buffer.d.ts +25 -0
  4. package/lib/captcha.d.ts +12 -0
  5. package/lib/consistent.d.ts +20 -0
  6. package/lib/core.d.ts +85 -0
  7. package/lib/crypto.d.ts +47 -0
  8. package/lib/db.d.ts +88 -0
  9. package/lib/dns.d.ts +75 -0
  10. package/lib/fs.d.ts +49 -0
  11. package/lib/jwt.d.ts +30 -0
  12. package/lib/kv.d.ts +111 -0
  13. package/lib/lan.d.ts +10 -0
  14. package/lib/net/formdata.d.ts +23 -0
  15. package/lib/net/request.d.ts +23 -0
  16. package/lib/net/response.d.ts +14 -0
  17. package/lib/net.d.ts +65 -0
  18. package/lib/s3.d.ts +35 -0
  19. package/lib/scan.d.ts +31 -0
  20. package/lib/session.d.ts +22 -0
  21. package/lib/sql.d.ts +57 -0
  22. package/lib/ssh/sftp.d.ts +40 -0
  23. package/lib/ssh/shell.d.ts +13 -0
  24. package/lib/ssh.d.ts +24 -0
  25. package/lib/text.d.ts +40 -0
  26. package/lib/time.d.ts +22 -0
  27. package/lib/ws.d.ts +87 -0
  28. package/lib/zip.d.ts +40 -0
  29. package/lib/zlib.d.ts +25 -0
  30. package/main.d.ts +1 -0
  31. package/package.json +1 -1
  32. package/sys/child.d.ts +1 -0
  33. package/sys/cmd.d.ts +1 -0
  34. package/sys/ctr.d.ts +96 -0
  35. package/sys/master.d.ts +1 -0
  36. package/sys/mod.d.ts +205 -0
  37. package/sys/route.d.ts +31 -0
  38. package/tsconfig.json +1 -1
  39. package/www/example/ctr/main.d.ts +4 -0
  40. package/www/example/ctr/middle.d.ts +6 -0
  41. package/www/example/ctr/test.d.ts +94 -0
  42. package/www/example/mod/test.d.ts +20 -0
  43. package/www/example/mod/testdata.d.ts +9 -0
  44. package/www/example/ws/mproxy.d.ts +4 -0
  45. package/www/example/ws/rproxy.d.ts +4 -0
  46. package/www/example/ws/test.d.ts +7 -0
  47. package/index.ts +0 -33
  48. package/lib/buffer.ts +0 -152
  49. package/lib/captcha.ts +0 -63
  50. package/lib/consistent.ts +0 -219
  51. package/lib/core.ts +0 -880
  52. package/lib/crypto.ts +0 -384
  53. package/lib/db.ts +0 -719
  54. package/lib/dns.ts +0 -405
  55. package/lib/fs.ts +0 -527
  56. package/lib/jwt.ts +0 -276
  57. package/lib/kv.ts +0 -1489
  58. package/lib/lan.ts +0 -87
  59. package/lib/net/formdata.ts +0 -166
  60. package/lib/net/request.ts +0 -150
  61. package/lib/net/response.ts +0 -59
  62. package/lib/net.ts +0 -662
  63. package/lib/s3.ts +0 -235
  64. package/lib/scan.ts +0 -364
  65. package/lib/session.ts +0 -230
  66. package/lib/sql.ts +0 -1149
  67. package/lib/ssh/sftp.ts +0 -508
  68. package/lib/ssh/shell.ts +0 -123
  69. package/lib/ssh.ts +0 -191
  70. package/lib/text.ts +0 -626
  71. package/lib/time.ts +0 -254
  72. package/lib/ws.ts +0 -523
  73. package/lib/zip.ts +0 -447
  74. package/lib/zlib.ts +0 -350
  75. package/main.ts +0 -27
  76. package/sys/child.ts +0 -678
  77. package/sys/cmd.ts +0 -225
  78. package/sys/ctr.ts +0 -904
  79. package/sys/master.ts +0 -355
  80. package/sys/mod.ts +0 -1871
  81. package/sys/route.ts +0 -1113
  82. package/www/example/ctr/main.ts +0 -9
  83. package/www/example/ctr/middle.ts +0 -26
  84. package/www/example/ctr/test.ts +0 -3218
  85. package/www/example/mod/test.ts +0 -47
  86. package/www/example/mod/testdata.ts +0 -30
  87. package/www/example/ws/mproxy.ts +0 -16
  88. package/www/example/ws/rproxy.ts +0 -14
  89. package/www/example/ws/test.ts +0 -36
package/sys/mod.d.ts ADDED
@@ -0,0 +1,205 @@
1
+ import * as lSql from '~/lib/sql';
2
+ import * as lDb from '~/lib/db';
3
+ import * as sCtr from '~/sys/ctr';
4
+ import * as types from '~/types';
5
+ declare class Rows<T extends Mod> implements types.Rows<T> {
6
+ private readonly _items;
7
+ constructor(initialItems?: T[]);
8
+ get length(): number;
9
+ item(index: number): T;
10
+ toArray(): Array<Record<string, any>>;
11
+ filter(predicate: (value: T, index: number) => boolean): Rows<T>;
12
+ map<TU>(allbackfn: (value: T, index: number) => TU): TU[];
13
+ [Symbol.iterator](): Iterator<T>;
14
+ }
15
+ export default class Mod {
16
+ protected static _$table: string;
17
+ protected static _$primary: string;
18
+ protected static _$key: string;
19
+ protected static _$soft: boolean;
20
+ protected _updates: Record<string, boolean>;
21
+ protected _data: Record<string, any>;
22
+ protected _index: string[] | null;
23
+ protected _contain: {
24
+ 'key': string;
25
+ 'list': string[];
26
+ } | null;
27
+ protected _total: number[];
28
+ protected _db: lDb.Pool | lDb.Transaction;
29
+ protected _sql: lSql.Sql;
30
+ protected _ctr?: sCtr.Ctr;
31
+ constructor(opt: {
32
+ 'db': lDb.Pool | lDb.Transaction;
33
+ 'ctr'?: sCtr.Ctr;
34
+ 'index'?: string | string[];
35
+ 'alias'?: string;
36
+ 'row'?: Record<string, any>;
37
+ 'select'?: string | string[];
38
+ 'where'?: string | types.Json;
39
+ 'contain'?: {
40
+ 'key': string;
41
+ 'list': string[];
42
+ };
43
+ 'raw'?: boolean;
44
+ 'pre'?: string;
45
+ });
46
+ static column(field: string): {
47
+ 'type': 'column';
48
+ 'token': string;
49
+ 'value': string;
50
+ };
51
+ static insert(db: lDb.Pool | lDb.Transaction, cs: string[] | Record<string, any>, vs?: any[] | any[][], opt?: {
52
+ 'pre'?: sCtr.Ctr | string;
53
+ 'index'?: string;
54
+ }): Promise<boolean | null | false>;
55
+ static insertSql(cs: string[] | Record<string, any>, vs?: any[] | any[][], opt?: {
56
+ 'pre'?: sCtr.Ctr | string;
57
+ 'index'?: string;
58
+ }): string;
59
+ static insertDuplicate(db: lDb.Pool | lDb.Transaction, data: Record<string, any>, update: types.Json, opt?: {
60
+ 'pre'?: sCtr.Ctr | string;
61
+ 'index'?: string;
62
+ }): Promise<boolean | null>;
63
+ static removeByWhere(db: lDb.Pool | lDb.Transaction, where: string | types.Json, opt?: {
64
+ 'raw'?: boolean;
65
+ 'pre'?: sCtr.Ctr | string;
66
+ 'index'?: string;
67
+ 'by'?: [string | string[], 'DESC' | 'ASC'];
68
+ 'limit'?: [number, number?];
69
+ }): Promise<number | false | null>;
70
+ static removeByWhereSql(db: lDb.Pool | lDb.Transaction, where: string | types.Json, opt?: {
71
+ 'raw'?: boolean;
72
+ 'pre'?: sCtr.Ctr | string;
73
+ 'index'?: string;
74
+ 'by'?: [string | string[], 'DESC' | 'ASC'];
75
+ 'limit'?: [number, number?];
76
+ }): lSql.Sql;
77
+ static updateByWhere(db: lDb.Pool | lDb.Transaction, data: types.Json, where: string | types.Json, opt?: {
78
+ 'raw'?: boolean;
79
+ 'pre'?: sCtr.Ctr | string;
80
+ 'index'?: string | string[];
81
+ 'by'?: [string | string[], 'DESC' | 'ASC'];
82
+ 'limit'?: [number, number?];
83
+ }): Promise<number | false | null>;
84
+ static updateByWhereSql(data: types.Json, where: string | types.Json, opt?: {
85
+ 'raw'?: boolean;
86
+ 'pre'?: sCtr.Ctr | string;
87
+ 'index'?: string;
88
+ 'by'?: [string | string[], 'DESC' | 'ASC'];
89
+ 'limit'?: [number, number?];
90
+ }): lSql.Sql;
91
+ static select<T extends Mod>(db: lDb.Pool | lDb.Transaction, c: string | string[], opt?: {
92
+ 'ctr'?: sCtr.Ctr;
93
+ 'pre'?: string;
94
+ 'index'?: string | string[];
95
+ 'alias'?: string;
96
+ 'contain'?: {
97
+ 'key': string;
98
+ 'list': string[];
99
+ };
100
+ }): T & Record<string, any>;
101
+ static where<T extends Mod>(db: lDb.Pool | lDb.Transaction, s?: string | types.Json, opt?: {
102
+ 'ctr'?: sCtr.Ctr;
103
+ 'raw'?: boolean;
104
+ 'pre'?: string;
105
+ 'index'?: string | string[];
106
+ 'contain'?: {
107
+ 'key': string;
108
+ 'list': string[];
109
+ };
110
+ }): T & Record<string, any>;
111
+ static getCreate<T extends Mod>(db: lDb.Pool | lDb.Transaction, opt?: {
112
+ 'ctr'?: sCtr.Ctr;
113
+ 'pre'?: string;
114
+ 'index'?: string;
115
+ }): T;
116
+ static find<T extends Mod>(db: lDb.Pool | lDb.Transaction, val: string | number | null, opt?: {
117
+ 'ctr'?: sCtr.Ctr;
118
+ 'lock'?: boolean;
119
+ 'raw'?: boolean;
120
+ 'pre'?: string;
121
+ 'index'?: string;
122
+ }): Promise<false | null | (T & Record<string, any>)>;
123
+ static one(db: lDb.Pool | lDb.Transaction, s: string | types.Json, opt: {
124
+ 'ctr'?: sCtr.Ctr;
125
+ 'raw'?: boolean;
126
+ 'pre'?: string;
127
+ 'index'?: string | string[];
128
+ 'select'?: string | string[];
129
+ 'by'?: [string | string[], 'DESC' | 'ASC'];
130
+ 'array': true;
131
+ }): Promise<false | null | Record<string, any>>;
132
+ static one<T extends Mod>(db: lDb.Pool | lDb.Transaction, s: string | types.Json, opt: {
133
+ 'ctr'?: sCtr.Ctr;
134
+ 'raw'?: boolean;
135
+ 'pre'?: string;
136
+ 'index'?: string | string[];
137
+ 'select'?: string | string[];
138
+ 'by'?: [string | string[], 'DESC' | 'ASC'];
139
+ 'array'?: false;
140
+ }): Promise<false | null | (T & Record<string, any>)>;
141
+ static oneArray(db: lDb.Pool | lDb.Transaction, s: string | types.Json, opt?: {
142
+ 'ctr'?: sCtr.Ctr;
143
+ 'raw'?: boolean;
144
+ 'pre'?: string;
145
+ 'index'?: string | string[];
146
+ 'select'?: string | string[];
147
+ }): Promise<false | null | Record<string, any>>;
148
+ static primarys(db: lDb.Pool | lDb.Transaction, where?: string | types.Json, opt?: {
149
+ 'ctr'?: sCtr.Ctr;
150
+ 'raw'?: boolean;
151
+ 'pre'?: string;
152
+ 'index'?: string;
153
+ }): Promise<any[] | false>;
154
+ static toArrayByRecord<T extends Mod>(obj: Record<string, T>): Record<string, Record<string, any>>;
155
+ set<T extends this, TK extends keyof T>(n: Record<TK, T[TK] | undefined>): void;
156
+ set<T extends this, TK extends keyof T>(n: TK, v: T[TK]): void;
157
+ get(n: string): any;
158
+ create(notWhere?: string | types.Json, table?: string): Promise<boolean>;
159
+ replace(): Promise<boolean>;
160
+ refresh(lock?: boolean): Promise<boolean | null>;
161
+ save(): Promise<boolean>;
162
+ remove(raw?: boolean): Promise<boolean>;
163
+ first(lock: boolean, array: true): Promise<false | null | Record<string, any>>;
164
+ first(lock?: boolean, array?: false): Promise<false | null | (this & Record<string, any>)>;
165
+ firstArray(lock?: boolean): Promise<Record<string, any> | false | null>;
166
+ union(f: lSql.Sql | string | types.IModUnionItem | string[] | types.IModUnionItem[], type?: string): this;
167
+ unionAll(f: lSql.Sql | string | types.IModUnionItem | string[] | types.IModUnionItem[]): this;
168
+ all(): Promise<false | Rows<this>>;
169
+ all(key: string): Promise<false | Record<string, this>>;
170
+ allArray(): Promise<false | Array<Record<string, any>>>;
171
+ allArray(key: string): Promise<false | Record<string, Record<string, any>>>;
172
+ explain(all?: false): Promise<false | string>;
173
+ explain(all: true): Promise<false | Record<string, any>>;
174
+ private _formatTotal;
175
+ total(f?: string): Promise<number>;
176
+ count(): Promise<number>;
177
+ join(f: string, s?: types.Json, type?: string, index?: string, pre?: string): this;
178
+ leftJoin(f: string, s: types.Json, index?: string, pre?: string): this;
179
+ rightJoin(f: string, s: types.Json, index?: string, pre?: string): this;
180
+ innerJoin(f: string, s: types.Json, index?: string, pre?: string): this;
181
+ fullJoin(f: string, s: types.Json, index?: string, pre?: string): this;
182
+ crossJoin(f: string, s: types.Json, index?: string, pre?: string): this;
183
+ having(s: types.Json): this;
184
+ filter(s: types.Json, raw?: boolean): this;
185
+ where(s: types.Json, raw?: boolean): this;
186
+ by(c: string | Array<string | string[]>, d?: 'DESC' | 'ASC'): this;
187
+ group(c: string | string[]): this;
188
+ private _limit;
189
+ limit(a: number, b?: number): this;
190
+ page(count: number, page?: number): this;
191
+ append(sql: string): this;
192
+ contain(contain: {
193
+ 'key': string;
194
+ 'list': string[];
195
+ }): this;
196
+ getSql(): string;
197
+ getData(): any[];
198
+ format(sql?: string, data?: any[]): string;
199
+ toArray(): Record<string, any>;
200
+ updates(): Record<string, any>;
201
+ unsaved(): boolean;
202
+ langText(col: string, lang: string): string;
203
+ protected _keyGenerator(): string;
204
+ }
205
+ export {};
package/sys/route.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import * as http from 'http';
2
+ import * as http2 from 'http2';
3
+ import * as net from 'net';
4
+ import * as sCtr from './ctr';
5
+ import * as types from '~/types';
6
+ export declare function clearKebabConfigs(): void;
7
+ export declare function run(data: {
8
+ 'req': http2.Http2ServerRequest | http.IncomingMessage;
9
+ 'res'?: http2.Http2ServerResponse | http.ServerResponse;
10
+ 'socket'?: net.Socket;
11
+ 'uri': types.IUrlParse;
12
+ 'rootPath': string;
13
+ 'urlBase': string;
14
+ 'path': string;
15
+ 'timer'?: {
16
+ 'timer': NodeJS.Timeout;
17
+ 'timeout': number;
18
+ 'callback': () => void;
19
+ };
20
+ }): Promise<boolean>;
21
+ export declare function unlinkUploadFiles(cctr: sCtr.Ctr | Record<string, types.IPostFile | types.IPostFile[]>): Promise<void>;
22
+ export declare function waitCtr(cctr: sCtr.Ctr): Promise<void>;
23
+ export declare function trimPost(post: Record<string, types.Json>): void;
24
+ export declare function getFormData(req: http2.Http2ServerRequest | http.IncomingMessage, events?: {
25
+ onfilestart?: (name: string) => boolean | undefined;
26
+ onfiledata?: (chunk: Buffer) => void;
27
+ onfileend?: () => void;
28
+ }): Promise<{
29
+ 'post': Record<string, types.Json>;
30
+ 'files': Record<string, types.IPostFile | types.IPostFile[]>;
31
+ } | false>;
package/tsconfig.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "sourceMap": false,
8
8
  "target": "ES2021",
9
9
  "strict": true, // 严格模式
10
- "declaration": false, // d.ts
10
+ "declaration": true, // d.ts
11
11
  "declarationMap": false, // d.ts 的 map
12
12
  "newLine": "LF",
13
13
  "paths": {
@@ -0,0 +1,4 @@
1
+ import * as ctr from '~/sys/ctr';
2
+ export default class extends ctr.Ctr {
3
+ index(): string;
4
+ }
@@ -0,0 +1,6 @@
1
+ import * as ctr from '~/sys/ctr';
2
+ import * as types from '~/types';
3
+ export default class extends ctr.Ctr {
4
+ onLoad(): string | boolean;
5
+ onUnload(rtn: string | boolean | types.DbValue[]): string | boolean | types.DbValue[];
6
+ }
@@ -0,0 +1,94 @@
1
+ import * as fs from 'fs';
2
+ import * as sCtr from '~/sys/ctr';
3
+ import * as types from '~/types';
4
+ export default class extends sCtr.Ctr {
5
+ private _internalUrl;
6
+ onLoad(): Array<string | number> | boolean;
7
+ onUnload(rtn: string | boolean | types.DbValue[]): string | boolean | types.DbValue[];
8
+ notfound(): string;
9
+ index(): string;
10
+ article(): string;
11
+ qs(): string;
12
+ view(): Promise<string>;
13
+ json(): Array<number | string | object> | object;
14
+ ctrXsrf(): string;
15
+ ctrXsrf1(): types.Json[];
16
+ ctrCheckinput(): string;
17
+ ctrCheckinput1(): Promise<types.Json[]>;
18
+ ctrLocale(): Promise<types.Json[] | string>;
19
+ ctrCachettl(): string;
20
+ ctrHttpcode(): string;
21
+ ctrCross(): string;
22
+ ctrCross1(): types.Json[];
23
+ ctrCross2(): types.Json[];
24
+ ctrReadable(): fs.ReadStream;
25
+ ctrAsynctask(): any[];
26
+ ctrTimeout(): Promise<any[]>;
27
+ modTest(): Promise<types.Json[] | string | boolean>;
28
+ modSplit(): Promise<string>;
29
+ modSplit1(): Promise<void>;
30
+ modSplit2(): Promise<types.Json[]>;
31
+ captchaFastbuild(): string;
32
+ captchaBase64(): string;
33
+ coreRandom(): string;
34
+ coreRand(): string;
35
+ coreConvert62(): string;
36
+ corePurify(): string;
37
+ coreChecktype(): string;
38
+ coreMuid(): string;
39
+ coreGetlog(): Promise<string>;
40
+ coreUpdatecode(): Promise<string>;
41
+ coreReload(): Promise<string>;
42
+ coreRestart(): Promise<string>;
43
+ coreGlobal(): Promise<string>;
44
+ crypto(): Promise<string>;
45
+ db(): Promise<types.Json>;
46
+ private _dbTable;
47
+ kv(): Promise<types.Json>;
48
+ net(): Promise<string>;
49
+ netPipe(): Promise<types.Json>;
50
+ netPost(): Promise<types.Json>;
51
+ netPost1(): string;
52
+ netPostString(): Promise<string>;
53
+ netPostString1(): types.Json[];
54
+ netOpen(): Promise<types.Json>;
55
+ netFormTest(): Promise<string>;
56
+ netUpload(): Promise<string>;
57
+ netUpload1(): Promise<string>;
58
+ netCookie(): Promise<string>;
59
+ netCookie1(): string;
60
+ netCookie2(): string;
61
+ netSave(): Promise<string>;
62
+ netFollow(): Promise<string>;
63
+ netFollow1(): void;
64
+ netFollow2(): types.Json;
65
+ netReuse(): Promise<string>;
66
+ netError(): Promise<string>;
67
+ netHosts(): Promise<string>;
68
+ netRproxy(): Promise<string | boolean>;
69
+ netMproxy(): Promise<string | boolean>;
70
+ netMproxy1(): Promise<string | boolean>;
71
+ scan(): Promise<types.Json>;
72
+ scan1(): Promise<types.Json>;
73
+ scan2(): Promise<types.Json>;
74
+ scan3(): Promise<types.Json>;
75
+ private _scanLink;
76
+ session(): Promise<string | types.Json[]>;
77
+ jwt(): Promise<string | types.Json[]>;
78
+ jwt1(): Promise<[number, types.Json]>;
79
+ sql(): string;
80
+ consistentHash(): string;
81
+ consistentDistributed(): string;
82
+ consistentMigration(): string;
83
+ consistentFast(): string;
84
+ text(): string;
85
+ time(): string;
86
+ wsServer(): string;
87
+ wsClient(): Promise<string>;
88
+ ssh(): Promise<string | types.Json[]>;
89
+ s3(): Promise<string>;
90
+ zip(): Promise<string>;
91
+ buffer(): string;
92
+ lan(): Promise<string>;
93
+ private _getEnd;
94
+ }
@@ -0,0 +1,20 @@
1
+ import sMod from '~/sys/mod';
2
+ import types from '~/types';
3
+ export default class extends sMod {
4
+ protected static _$table: string;
5
+ protected static _$primary: string;
6
+ protected static _$key: string;
7
+ id: number;
8
+ token: string;
9
+ point: {
10
+ 'x': number;
11
+ 'y': number;
12
+ };
13
+ polygon: Array<Array<{
14
+ 'x': number;
15
+ 'y': number;
16
+ }>>;
17
+ json: types.Json;
18
+ time_add: number;
19
+ protected _keyGenerator(): string;
20
+ }
@@ -0,0 +1,9 @@
1
+ import sMod from '~/sys/mod';
2
+ export default class extends sMod {
3
+ protected static _$table: string;
4
+ protected static _$primary: string;
5
+ id: number;
6
+ test_id: number;
7
+ content: string;
8
+ time_add: number;
9
+ }
@@ -0,0 +1,4 @@
1
+ import * as sCtr from '~/sys/ctr';
2
+ export default class extends sCtr.Ctr {
3
+ onLoad(): Promise<boolean>;
4
+ }
@@ -0,0 +1,4 @@
1
+ import * as sCtr from '~/sys/ctr';
2
+ export default class extends sCtr.Ctr {
3
+ onLoad(): Promise<boolean>;
4
+ }
@@ -0,0 +1,7 @@
1
+ import * as sCtr from '~/sys/ctr';
2
+ export default class extends sCtr.Ctr {
3
+ private _nick;
4
+ onLoad(): boolean;
5
+ onData(data: Buffer | string): string;
6
+ onClose(): void;
7
+ }
package/index.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * Project: Kebab, User: JianSuoQiYue
3
- * Date: 2019-3-30 12:46:41
4
- * Last: 2020-3-8 21:04:24, 2022-07-22 14:20:34, 2023-5-24 01:34:57, 2025-6-13 14:49:27
5
- * --- 本文件用来定义每个目录实体地址的常量 ---
6
- */
7
-
8
- /** --- 当前系统版本号 --- */
9
- export const VER = '2.0.3';
10
-
11
- // --- 服务端用的路径 ---
12
-
13
- /** --- /xxx/xxx --- */
14
- const dirname = __dirname.replace(/\\/g, '/');
15
-
16
- /** --- 框架根目录,以 / 结尾 --- */
17
- export const ROOT_PATH = dirname + '/';
18
- export const LIB_PATH = ROOT_PATH + 'lib/';
19
- export const SYS_PATH = ROOT_PATH + 'sys/';
20
-
21
- const cwd = process.cwd().replace(/\\/g, '/');
22
-
23
- /** --- 执行根目录,以 / 结尾 --- */
24
- export const ROOT_CWD = cwd + '/';
25
- export const CONF_CWD = ROOT_CWD + 'conf/';
26
- export const CERT_CWD = CONF_CWD + 'cert/';
27
- export const VHOST_CWD = CONF_CWD + 'vhost/';
28
- export const LIB_CWD = ROOT_CWD + 'lib/';
29
- export const LOG_CWD = ROOT_CWD + 'log/';
30
- export const WWW_CWD = ROOT_CWD + 'www/';
31
- export const IND_CWD = ROOT_CWD + 'ind/';
32
- export const FTMP_CWD = ROOT_CWD + 'ftmp/';
33
- export const MOD_CWD = ROOT_CWD + 'mod/';
package/lib/buffer.ts DELETED
@@ -1,152 +0,0 @@
1
- /** --- 读对象 --- */
2
- export class Reader {
3
-
4
- private readonly _buffer: Buffer;
5
-
6
- /** --- 当前读取位置 --- */
7
- private _offset: number = 0;
8
-
9
- public constructor(buffer: Buffer) {
10
- this._buffer = buffer;
11
- }
12
-
13
- /** --- 读取一个无符号8位整数, BYTE --- */
14
- public readUInt8(): number {
15
- const value = this._buffer.readUInt8(this._offset);
16
- this._offset += 1;
17
- return value;
18
- }
19
-
20
- /** --- 读取一个无符号16位整数(大端模式),WORD --- */
21
- public readUInt16BE(): number {
22
- const value = this._buffer.readUInt16BE(this._offset);
23
- this._offset += 2;
24
- return value;
25
- }
26
-
27
- /** --- 读取一个无符号32位整数(大端模式), DWORD --- */
28
- public readUInt32BE(): number {
29
- const value = this._buffer.readUInt32BE(this._offset);
30
- this._offset += 4;
31
- return value;
32
- }
33
-
34
- /** --- 读取一个 BCD 编码的字符串(每个字节表示两个数字)--- */
35
- public readBCDString(length?: number): string {
36
- if (length === undefined) {
37
- length = this._buffer.length - this._offset;
38
- }
39
- let str = '';
40
- for (let i = 0; i < length; i++) {
41
- const byte = this._buffer.readUInt8(this._offset + i);
42
- str += (byte >> 4).toString(16).toUpperCase(); // --- 高四位表示第一个数字 ---
43
- str += (byte & 0x0f).toString(16).toUpperCase(); // --- 低四位表示第二个数字 ---
44
- }
45
- this._offset += length;
46
- return str;
47
- }
48
-
49
- /** --- 读取普通 string --- */
50
- public readString(length?: number, encoding: BufferEncoding = 'utf8'): string {
51
- if (length === undefined) {
52
- length = this._buffer.length - this._offset;
53
- }
54
- const buf: number[] = [];
55
- for (let i = 0; i < length; i++) {
56
- const byte = this._buffer.readUInt8(this._offset + i);
57
- if (byte === 0x00) {
58
- continue;
59
- }
60
- buf.push(byte);
61
- }
62
- this._offset += length;
63
- return Buffer.from(buf).toString(encoding);
64
- }
65
-
66
- /** --- 读取 Buffer --- */
67
- public readBuffer(length?: number): Buffer {
68
- if (length === undefined) {
69
- length = this._buffer.length - this._offset;
70
- }
71
- return this._buffer.subarray(this._offset, this._offset += length);
72
- }
73
-
74
- /** --- 获取完整的 buffer 长度 --- */
75
- public length(): number {
76
- return this._buffer.length;
77
- }
78
-
79
- }
80
-
81
- /** --- 写对象 --- */
82
- export class Writer {
83
-
84
- private readonly _buffer: Buffer;
85
-
86
- /** --- 当前读取位置 --- */
87
- private _offset: number = 0;
88
-
89
- public constructor(size: number) {
90
- this._buffer = Buffer.alloc(size);
91
- }
92
-
93
- /** --- [1 字节] 写入一个无符号 8 位整数 --- */
94
- public writeUInt8(value: number): void {
95
- this._buffer.writeUInt8(value, this._offset);
96
- this._offset += 1;
97
- }
98
-
99
- /** --- [2 字节] 写入一个无符号 16 位整数(大端模式) --- */
100
- public writeUInt16BE(value: number): void {
101
- this._buffer.writeUInt16BE(value, this._offset);
102
- this._offset += 2;
103
- }
104
-
105
- /** --- [4 字节] 写入一个无符号 32 位整数(大端模式) --- */
106
- public writeUInt32BE(value: number): void {
107
- this._buffer.writeUint32BE(value, this._offset);
108
- this._offset += 4;
109
- }
110
-
111
- /** --- [每字节 2 数字] 写入一个 BCD 编码的字符串(仅支持数字) --- */
112
- public writeBCDString(value: string): void {
113
- for (let i = 0; i < value.length; i += 2) {
114
- const high = parseInt(value[i], 10); // --- 取十位 ---
115
- const low = parseInt(value[i + 1], 10); // --- 取个位 ---
116
- const byte = (high << 4) | low; // --- 拼接为一个字节 ---
117
- this.writeUInt8(byte);
118
- }
119
- }
120
-
121
- /** --- 写入普通字符串,返回写入的长度 --- */
122
- public writeString(value: string, encoding: BufferEncoding = 'utf8'): number {
123
- const bytes = Buffer.from(value, encoding);
124
- for (const byte of bytes) {
125
- this.writeUInt8(byte);
126
- }
127
- this._offset += bytes.length;
128
- return bytes.length;
129
- }
130
-
131
- /** --- 返回 Buffer 对象 --- */
132
- public get(): Buffer {
133
- return this._buffer.subarray(0, this._offset);
134
- }
135
-
136
- }
137
-
138
- /**
139
- * --- Buffer Reader 对象 ---
140
- * @param buffer 要读取的 buffer
141
- */
142
- export function getReader(buffer: Buffer): Reader {
143
- return new Reader(buffer);
144
- }
145
-
146
- /**
147
- * --- Buffer Writer 对象 ---
148
- * @param buffer 要读取的 buffer
149
- */
150
- export function getWriter(size: number): Writer {
151
- return new Writer(size);
152
- }
package/lib/captcha.ts DELETED
@@ -1,63 +0,0 @@
1
- /**
2
- * Project: Kebab, User: JianSuoQiYue
3
- * Date: 2019-6-7 12:14:31
4
- * Last: 2020-3-11 23:33:19, 2022-09-12 10:38:24, 2022-12-29 01:16:26, 2024-4-1 16:40:42, 2025-6-13 19:45:30
5
- */
6
- import * as svgCaptcha from 'svg-captcha';
7
- import * as mime from '@litert/mime';
8
- import * as core from '~/lib/core';
9
- import * as kebab from '~/index';
10
-
11
- svgCaptcha.loadFont(kebab.LIB_PATH + 'captcha/zcool-addict-italic.ttf');
12
-
13
- export class Captcha {
14
-
15
- private readonly _link: svgCaptcha.CaptchaObj;
16
-
17
- public constructor(opt: { 'width': number; 'height': number; 'length': number; }) {
18
- this._link = svgCaptcha.create({
19
- 'width': opt.width,
20
- 'height': opt.height,
21
- 'size': opt.length,
22
- 'noise': 15,
23
- 'background': '#fff',
24
- 'charPreset': core.RANDOM_V
25
- });
26
- }
27
-
28
- /**
29
- * --- 获取图片 Buffer ---
30
- */
31
- public getBuffer(): string {
32
- return this._link.data.replace('<rect width="100%" height="100%" fill="#fff"/>', '');
33
- }
34
-
35
- /**
36
- * --- 获取 base64 格式图片 ---
37
- */
38
- public getBase64(): string {
39
- return `data:${mime.getMime('svg')};base64,` + Buffer.from(this._link.data.replace('<rect width="100%" height="100%" fill="#fff"/>', '')).toString('base64');
40
- }
41
-
42
- /**
43
- * --- 获取当前随机码 ---
44
- */
45
- public getPhrase(): string {
46
- return this._link.text;
47
- }
48
-
49
- }
50
-
51
- /**
52
- * --- 获取验证码对象 ---
53
- * @param width 宽度
54
- * @param height 高度
55
- * @param length 字符个数
56
- */
57
- export function get(width: number, height: number, length: number = 4): Captcha {
58
- return new Captcha({
59
- 'width': width,
60
- 'height': height,
61
- 'length': length
62
- });
63
- }