@maiyunnet/kebab 9.22.2 → 9.22.3

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/doc/kebab-rag.md CHANGED
@@ -1717,7 +1717,7 @@ index/variables/VER.md
1717
1717
 
1718
1718
  # Variable: VER
1719
1719
 
1720
- > `const` **VER**: `"9.22.2"` = `'9.22.2'`
1720
+ > `const` **VER**: `"9.22.3"` = `'9.22.3'`
1721
1721
 
1722
1722
  Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
1723
1723
 
@@ -133898,19 +133898,9 @@ Defined in: [sys/ctr.ts:1256](https://github.com/maiyunnet/kebab/blob/master/sys
133898
133898
 
133899
133899
  ##### events?
133900
133900
 
133901
- 文件处理情况
133902
-
133903
- ###### onfiledata?
133904
-
133905
- (`chunk`) => `void`
133906
-
133907
- ###### onfileend?
133901
+ [`IFormDataEvents`](../../route/interfaces/IFormDataEvents.md) = `{}`
133908
133902
 
133909
- () => `void`
133910
-
133911
- ###### onfilestart?
133912
-
133913
- (`name`) => `boolean` \| `undefined`
133903
+ 文件处理情况
133914
133904
 
133915
133905
  ##### limits?
133916
133906
 
@@ -133922,7 +133912,7 @@ Defined in: [sys/ctr.ts:1256](https://github.com/maiyunnet/kebab/blob/master/sys
133922
133912
 
133923
133913
  `Promise`\<`boolean`\>
133924
133914
 
133925
- 是否解析成功;失败原因通过 limits.onError 通知,连接中断时可能无法发送响应
133915
+ 是否解析成功;失败原因通过 events.onerror 通知,连接中断时可能无法发送响应
133926
133916
 
133927
133917
  ***
133928
133918
 
@@ -138122,7 +138112,7 @@ sys/route/functions/getFormData.md
138122
138112
 
138123
138113
  > **getFormData**(`req`, `events?`, `limits?`): `Promise`\<`false` \| \{ `files`: `Record`\<`string`, [`IPostFile`](../../../index/interfaces/IPostFile.md) \| [`IPostFile`](../../../index/interfaces/IPostFile.md)[]\>; `post`: `Record`\<`string`, [`Json`](../../../index/type-aliases/Json.md)\>; \}\>
138124
138114
 
138125
- Defined in: [sys/route.ts:1069](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1069)
138115
+ Defined in: [sys/route.ts:1079](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1079)
138126
138116
 
138127
138117
  获取 formdata 的 post
138128
138118
 
@@ -138136,25 +138126,9 @@ Defined in: [sys/route.ts:1069](https://github.com/maiyunnet/kebab/blob/master/s
138136
138126
 
138137
138127
  ### events?
138138
138128
 
138139
- 文件处理情况
138140
-
138141
- #### onfiledata?
138142
-
138143
- (`chunk`) => `void`
138144
-
138145
- 文件上传时触发,仅 start 返回 true 时触发
138146
-
138147
- #### onfileend?
138148
-
138149
- () => `void`
138150
-
138151
- 文件上传结束时触发,仅 start 返回 true 时触发
138152
-
138153
- #### onfilestart?
138129
+ [`IFormDataEvents`](../interfaces/IFormDataEvents.md) = `{}`
138154
138130
 
138155
- (`name`) => `boolean` \| `undefined`
138156
-
138157
- 文件开始上传时触发,返回 true 则跳过该文件的保存
138131
+ 文件处理情况
138158
138132
 
138159
138133
  ### limits?
138160
138134
 
@@ -138166,7 +138140,7 @@ Defined in: [sys/route.ts:1069](https://github.com/maiyunnet/kebab/blob/master/s
138166
138140
 
138167
138141
  `Promise`\<`false` \| \{ `files`: `Record`\<`string`, [`IPostFile`](../../../index/interfaces/IPostFile.md) \| [`IPostFile`](../../../index/interfaces/IPostFile.md)[]\>; `post`: `Record`\<`string`, [`Json`](../../../index/type-aliases/Json.md)\>; \}\>
138168
138142
 
138169
- 字段和临时文件;失败返回 false,并通过 limits.onError 通知首次失败原因
138143
+ 字段和临时文件;失败返回 false,并通过 events.onerror 通知首次失败原因
138170
138144
 
138171
138145
  sys/route/functions/getPost.md
138172
138146
  ---
@@ -138359,6 +138333,7 @@ sys/route/index.md
138359
138333
  ## Interfaces
138360
138334
 
138361
138335
  - [IFormDataError](interfaces/IFormDataError.md)
138336
+ - [IFormDataEvents](interfaces/IFormDataEvents.md)
138362
138337
  - [IFormDataLimits](interfaces/IFormDataLimits.md)
138363
138338
 
138364
138339
  ## Functions
@@ -138403,6 +138378,95 @@ Defined in: [sys/route.ts:1039](https://github.com/maiyunnet/kebab/blob/master/s
138403
138378
 
138404
138379
  触发的限制值;大小按字节,超时按毫秒,段数按个
138405
138380
 
138381
+ sys/route/interfaces/IFormDataEvents.md
138382
+ ---
138383
+
138384
+ [**Documents for @maiyunnet/kebab**](../../../index.md)
138385
+
138386
+ ***
138387
+
138388
+ [Documents for @maiyunnet/kebab](../../../index.md) / [sys/route](../index.md) / IFormDataEvents
138389
+
138390
+ # Interface: IFormDataEvents
138391
+
138392
+ Defined in: [sys/route.ts:1043](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1043)
138393
+
138394
+ multipart 文件处理及失败通知
138395
+
138396
+ ## Properties
138397
+
138398
+ ### onerror?
138399
+
138400
+ > `optional` **onerror?**: (`error`) => `void`
138401
+
138402
+ Defined in: [sys/route.ts:1051](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1051)
138403
+
138404
+ 首次失败时通知一次;原有 false 返回值不变,连接中断时响应可能无法送达
138405
+
138406
+ #### Parameters
138407
+
138408
+ ##### error
138409
+
138410
+ [`IFormDataError`](IFormDataError.md)
138411
+
138412
+ #### Returns
138413
+
138414
+ `void`
138415
+
138416
+ ***
138417
+
138418
+ ### onfiledata?
138419
+
138420
+ > `optional` **onfiledata?**: (`chunk`) => `void`
138421
+
138422
+ Defined in: [sys/route.ts:1047](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1047)
138423
+
138424
+ 文件上传时触发,仅 start 返回 true 时触发
138425
+
138426
+ #### Parameters
138427
+
138428
+ ##### chunk
138429
+
138430
+ `Buffer`
138431
+
138432
+ #### Returns
138433
+
138434
+ `void`
138435
+
138436
+ ***
138437
+
138438
+ ### onfileend?
138439
+
138440
+ > `optional` **onfileend?**: () => `void`
138441
+
138442
+ Defined in: [sys/route.ts:1049](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1049)
138443
+
138444
+ 文件上传结束时触发,仅 start 返回 true 时触发
138445
+
138446
+ #### Returns
138447
+
138448
+ `void`
138449
+
138450
+ ***
138451
+
138452
+ ### onfilestart?
138453
+
138454
+ > `optional` **onfilestart?**: (`name`) => `boolean` \| `undefined`
138455
+
138456
+ Defined in: [sys/route.ts:1045](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1045)
138457
+
138458
+ 文件开始上传时触发,返回 true 则跳过该文件的保存
138459
+
138460
+ #### Parameters
138461
+
138462
+ ##### name
138463
+
138464
+ `string`
138465
+
138466
+ #### Returns
138467
+
138468
+ `boolean` \| `undefined`
138469
+
138406
138470
  sys/route/interfaces/IFormDataLimits.md
138407
138471
  ---
138408
138472
 
@@ -138414,9 +138478,9 @@ sys/route/interfaces/IFormDataLimits.md
138414
138478
 
138415
138479
  # Interface: IFormDataLimits
138416
138480
 
138417
- Defined in: [sys/route.ts:1043](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1043)
138481
+ Defined in: [sys/route.ts:1055](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1055)
138418
138482
 
138419
- multipart 上传限制及失败通知
138483
+ multipart 上传限制
138420
138484
 
138421
138485
  ## Properties
138422
138486
 
@@ -138424,7 +138488,7 @@ multipart 上传限制及失败通知
138424
138488
 
138425
138489
  > `optional` **allowedExts?**: `string`[]
138426
138490
 
138427
- Defined in: [sys/route.ts:1047](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1047)
138491
+ Defined in: [sys/route.ts:1059](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1059)
138428
138492
 
138429
138493
  允许的文件扩展名(含点号),如 ['.jpg', '.png', '.pdf']
138430
138494
 
@@ -138434,7 +138498,7 @@ Defined in: [sys/route.ts:1047](https://github.com/maiyunnet/kebab/blob/master/s
138434
138498
 
138435
138499
  > `optional` **maxFieldSize?**: `number`
138436
138500
 
138437
- Defined in: [sys/route.ts:1049](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1049)
138501
+ Defined in: [sys/route.ts:1061](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1061)
138438
138502
 
138439
138503
  单个字段(非文件)最大字节数,默认 1 MB
138440
138504
 
@@ -138444,7 +138508,7 @@ Defined in: [sys/route.ts:1049](https://github.com/maiyunnet/kebab/blob/master/s
138444
138508
 
138445
138509
  > `optional` **maxFileSize?**: `number`
138446
138510
 
138447
- Defined in: [sys/route.ts:1045](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1045)
138511
+ Defined in: [sys/route.ts:1057](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1057)
138448
138512
 
138449
138513
  单个文件最大字节数
138450
138514
 
@@ -138454,7 +138518,7 @@ Defined in: [sys/route.ts:1045](https://github.com/maiyunnet/kebab/blob/master/s
138454
138518
 
138455
138519
  > `optional` **maxHeaderSize?**: `number`
138456
138520
 
138457
- Defined in: [sys/route.ts:1053](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1053)
138521
+ Defined in: [sys/route.ts:1065](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1065)
138458
138522
 
138459
138523
  单个 multipart 段头部最大字节数,默认 16 KB
138460
138524
 
@@ -138464,7 +138528,7 @@ Defined in: [sys/route.ts:1053](https://github.com/maiyunnet/kebab/blob/master/s
138464
138528
 
138465
138529
  > `optional` **maxParts?**: `number`
138466
138530
 
138467
- Defined in: [sys/route.ts:1055](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1055)
138531
+ Defined in: [sys/route.ts:1067](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1067)
138468
138532
 
138469
138533
  multipart 字段与文件总数量,默认 1000
138470
138534
 
@@ -138474,36 +138538,16 @@ multipart 字段与文件总数量,默认 1000
138474
138538
 
138475
138539
  > `optional` **maxTotalSize?**: `number`
138476
138540
 
138477
- Defined in: [sys/route.ts:1051](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1051)
138541
+ Defined in: [sys/route.ts:1063](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1063)
138478
138542
 
138479
138543
  整体请求最大字节数,不设置或设为 0 则不限制
138480
138544
 
138481
138545
  ***
138482
138546
 
138483
- ### onError?
138484
-
138485
- > `optional` **onError?**: (`error`) => `void`
138486
-
138487
- Defined in: [sys/route.ts:1059](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1059)
138488
-
138489
- 首次失败时通知一次;原有 false 返回值不变,连接中断时响应可能无法送达
138490
-
138491
- #### Parameters
138492
-
138493
- ##### error
138494
-
138495
- [`IFormDataError`](IFormDataError.md)
138496
-
138497
- #### Returns
138498
-
138499
- `void`
138500
-
138501
- ***
138502
-
138503
138547
  ### timeout?
138504
138548
 
138505
138549
  > `optional` **timeout?**: `number`
138506
138550
 
138507
- Defined in: [sys/route.ts:1057](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1057)
138551
+ Defined in: [sys/route.ts:1069](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1069)
138508
138552
 
138509
138553
  整体请求超时时间(毫秒),默认 5 分钟,设为 0 禁用超时
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "9.22.2";
8
+ export declare const VER = "9.22.3";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  /** --- 框架的 LIB,以 / 结尾 --- */
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '9.22.2';
9
+ export const VER = '9.22.3';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "9.22.2",
3
+ "version": "9.22.3",
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": [
package/sys/ctr.d.ts CHANGED
@@ -423,11 +423,7 @@ export declare class Ctr {
423
423
  * --- 获取 formdata 的信息 ---
424
424
  * @param events 文件处理情况
425
425
  * @param limits 上传限制
426
- * @returns 是否解析成功;失败原因通过 limits.onError 通知,连接中断时可能无法发送响应
426
+ * @returns 是否解析成功;失败原因通过 events.onerror 通知,连接中断时可能无法发送响应
427
427
  */
428
- protected _handleFormData(events?: {
429
- onfilestart?: (name: string) => boolean | undefined;
430
- onfiledata?: (chunk: Buffer) => void;
431
- onfileend?: () => void;
432
- }, limits?: sRoute.IFormDataLimits): Promise<boolean>;
428
+ protected _handleFormData(events?: sRoute.IFormDataEvents, limits?: sRoute.IFormDataLimits): Promise<boolean>;
433
429
  }
package/sys/ctr.js CHANGED
@@ -971,7 +971,7 @@ export class Ctr {
971
971
  * --- 获取 formdata 的信息 ---
972
972
  * @param events 文件处理情况
973
973
  * @param limits 上传限制
974
- * @returns 是否解析成功;失败原因通过 limits.onError 通知,连接中断时可能无法发送响应
974
+ * @returns 是否解析成功;失败原因通过 events.onerror 通知,连接中断时可能无法发送响应
975
975
  */
976
976
  async _handleFormData(events = {}, limits = {}) {
977
977
  const rtn = await sRoute.getFormData(this._req, events, limits);
package/sys/route.d.ts CHANGED
@@ -64,7 +64,18 @@ export interface IFormDataError {
64
64
  /** --- 触发的限制值;大小按字节,超时按毫秒,段数按个 --- */
65
65
  'limit'?: number;
66
66
  }
67
- /** --- multipart 上传限制及失败通知 --- */
67
+ /** --- multipart 文件处理及失败通知 --- */
68
+ export interface IFormDataEvents {
69
+ /** --- 文件开始上传时触发,返回 true 则跳过该文件的保存 --- */
70
+ onfilestart?: (name: string) => boolean | undefined;
71
+ /** --- 文件上传时触发,仅 start 返回 true 时触发 --- */
72
+ onfiledata?: (chunk: Buffer) => void;
73
+ /** --- 文件上传结束时触发,仅 start 返回 true 时触发 --- */
74
+ onfileend?: () => void;
75
+ /** --- 首次失败时通知一次;原有 false 返回值不变,连接中断时响应可能无法送达 --- */
76
+ onerror?: (error: IFormDataError) => void;
77
+ }
78
+ /** --- multipart 上传限制 --- */
68
79
  export interface IFormDataLimits {
69
80
  /** --- 单个文件最大字节数 --- */
70
81
  'maxFileSize'?: number;
@@ -80,26 +91,15 @@ export interface IFormDataLimits {
80
91
  'maxParts'?: number;
81
92
  /** --- 整体请求超时时间(毫秒),默认 5 分钟,设为 0 禁用超时 --- */
82
93
  'timeout'?: number;
83
- /** --- 首次失败时通知一次;原有 false 返回值不变,连接中断时响应可能无法送达 --- */
84
- 'onError'?: (error: IFormDataError) => void;
85
94
  }
86
95
  /**
87
96
  * --- 获取 formdata 的 post ---
88
97
  * @param req 请求头
89
98
  * @param events 文件处理情况
90
99
  * @param limits 文件上传限制
91
- * @returns 字段和临时文件;失败返回 false,并通过 limits.onError 通知首次失败原因
100
+ * @returns 字段和临时文件;失败返回 false,并通过 events.onerror 通知首次失败原因
92
101
  */
93
- export declare function getFormData(req: http2.Http2ServerRequest | http.IncomingMessage, events?: {
94
- /**
95
- * --- 文件开始上传时触发,返回 true 则跳过该文件的保存 ---
96
- */
97
- onfilestart?: (name: string) => boolean | undefined;
98
- /** --- 文件上传时触发,仅 start 返回 true 时触发 --- */
99
- onfiledata?: (chunk: Buffer) => void;
100
- /** --- 文件上传结束时触发,仅 start 返回 true 时触发 --- */
101
- onfileend?: () => void;
102
- }, limits?: IFormDataLimits): Promise<{
102
+ export declare function getFormData(req: http2.Http2ServerRequest | http.IncomingMessage, events?: IFormDataEvents, limits?: IFormDataLimits): Promise<{
103
103
  'post': Record<string, kebab.Json>;
104
104
  'files': Record<string, kebab.IPostFile | kebab.IPostFile[]>;
105
105
  } | false>;
package/sys/route.js CHANGED
@@ -964,7 +964,7 @@ export function getPost(req) {
964
964
  * @param req 请求头
965
965
  * @param events 文件处理情况
966
966
  * @param limits 文件上传限制
967
- * @returns 字段和临时文件;失败返回 false,并通过 limits.onError 通知首次失败原因
967
+ * @returns 字段和临时文件;失败返回 false,并通过 events.onerror 通知首次失败原因
968
968
  */
969
969
  export function getFormData(req, events = {}, limits = {}) {
970
970
  return new Promise(resolve => {
@@ -991,7 +991,7 @@ export function getFormData(req, events = {}, limits = {}) {
991
991
  /** --- 获取的 boundary 文本 --- */
992
992
  const boundary = boundaryMatch[1] ?? boundaryMatch[2];
993
993
  if (!boundary || (boundary.length > 200) || /[\r\n]/.test(boundary)) {
994
- limits.onError?.({ 'code': 'INVALID_BOUNDARY' });
994
+ events.onerror?.({ 'code': 'INVALID_BOUNDARY' });
995
995
  resolve(false);
996
996
  return;
997
997
  }
@@ -1038,20 +1038,17 @@ export function getFormData(req, events = {}, limits = {}) {
1038
1038
  let readEnd = false;
1039
1039
  /** --- 是否有文件被限制拒绝(整体返回 false) --- */
1040
1040
  let rejected = false;
1041
- /** --- 保留首次失败,避免清理产生的流错误覆盖实际原因 --- */
1042
- let failure;
1043
1041
  /**
1044
1042
  * --- 拒绝本次上传,继续读取请求以便正常返回错误响应 ---
1045
1043
  * @param error 首次失败原因及对应限制
1046
1044
  * @returns 无返回值
1047
1045
  */
1048
1046
  function reject(error) {
1049
- rejected = true;
1050
- if (failure) {
1047
+ if (rejected) {
1051
1048
  return;
1052
1049
  }
1053
- failure = error;
1054
- limits.onError?.(error);
1050
+ rejected = true;
1051
+ events.onerror?.(error);
1055
1052
  if (error.code !== 'REQUEST_ABORTED') {
1056
1053
  lCore.log({}, `[ROUTE][GETFORMDATA] rejected: ${error.code}, limit: ${error.limit ?? '-'}`, '-error');
1057
1054
  }
@@ -1118,7 +1115,6 @@ export function getFormData(req, events = {}, limits = {}) {
1118
1115
  reject({ 'code': 'TIMEOUT', 'limit': timeoutMs });
1119
1116
  cleanupActiveFile();
1120
1117
  lCore.debug('[ROUTE][GETFORMDATA] formdata request timeout');
1121
- lCore.log({}, '[ROUTE][GETFORMDATA] formdata request timeout after ' + timeoutMs + 'ms', '-error');
1122
1118
  cleanupFiles();
1123
1119
  resolve(false);
1124
1120
  }, timeoutMs);
@@ -1236,7 +1232,6 @@ export function getFormData(req, events = {}, limits = {}) {
1236
1232
  ftmpName = '';
1237
1233
  }
1238
1234
  --writeFileLength;
1239
- req.resume();
1240
1235
  lCore.log({}, `[ROUTE][GETFORMDATA] temporary file error: ${error.message}`, '-error');
1241
1236
  if (readEnd) {
1242
1237
  finalize();