@midwayjs/busboy 4.0.0-alpha.1 → 4.0.0-beta.2

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/README.md CHANGED
@@ -9,4 +9,4 @@ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
12
- [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
12
+ [MIT]((https://github.com/midwayjs/midway/blob/master/LICENSE))
@@ -36,6 +36,10 @@ export interface UploadOptions extends BusboyConfig {
36
36
  * Mime type white list
37
37
  */
38
38
  mimeTypeWhiteList?: Record<string, string | string[]> | ((ctx: IMidwayContext<any>) => string | string[]);
39
+ /**
40
+ * Whether to allow fields duplication, default is `false`, only for `file` and `stream` mode
41
+ */
42
+ allowFieldsDuplication?: boolean;
39
43
  }
40
44
  export interface UploadFileInfo {
41
45
  /**
@@ -119,7 +119,7 @@ let UploadMiddleware = class UploadMiddleware {
119
119
  }
120
120
  async processFileOrStream(req, uploadConfig, currentContextWhiteListMap, currentContextMimeTypeWhiteListMap, ctxOrReq) {
121
121
  let isStreamResolve = false;
122
- const { mode, tmpdir } = uploadConfig;
122
+ const { mode, tmpdir, allowFieldsDuplication } = uploadConfig;
123
123
  const { files = [], fields = [] } = await new Promise((resolveP, reject) => {
124
124
  const bb = busboy({
125
125
  headers: req.headers,
@@ -219,10 +219,27 @@ let UploadMiddleware = class UploadMiddleware {
219
219
  req.pipe(bb);
220
220
  });
221
221
  ctxOrReq.files = files;
222
- ctxOrReq.fields = fields.reduce((accumulator, current) => {
223
- accumulator[current.name] = current.value;
224
- return accumulator;
225
- }, {});
222
+ if (allowFieldsDuplication) {
223
+ // 如果重复,则使用数组
224
+ ctxOrReq.fields = fields.reduce((accumulator, current) => {
225
+ if (accumulator[current.name]) {
226
+ if (!Array.isArray(accumulator[current.name])) {
227
+ accumulator[current.name] = [accumulator[current.name]];
228
+ }
229
+ accumulator[current.name].push(current.value);
230
+ }
231
+ else {
232
+ accumulator[current.name] = current.value;
233
+ }
234
+ return accumulator;
235
+ }, {});
236
+ }
237
+ else {
238
+ ctxOrReq.fields = fields.reduce((accumulator, current) => {
239
+ accumulator[current.name] = current.value;
240
+ return accumulator;
241
+ }, {});
242
+ }
226
243
  }
227
244
  async processAsyncIterator(req, uploadConfig, currentContextWhiteListMap, currentContextMimeTypeWhiteListMap, ctxOrReq) {
228
245
  const bb = busboy({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/busboy",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-beta.2",
4
4
  "description": "Midway Component for upload",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "index.d.ts"
19
19
  ],
20
20
  "engines": {
21
- "node": ">=12"
21
+ "node": ">=20"
22
22
  },
23
23
  "license": "MIT",
24
24
  "dependencies": {
@@ -27,14 +27,14 @@
27
27
  "file-type": "16.5.4"
28
28
  },
29
29
  "devDependencies": {
30
- "@midwayjs/core": "^4.0.0-alpha.1",
31
- "@midwayjs/express": "^4.0.0-alpha.1",
32
- "@midwayjs/faas": "^4.0.0-alpha.1",
33
- "@midwayjs/fc-starter": "^4.0.0-alpha.1",
34
- "@midwayjs/koa": "^4.0.0-alpha.1",
35
- "@midwayjs/mock": "^4.0.0-alpha.1",
36
- "@midwayjs/web": "^4.0.0-alpha.1",
30
+ "@midwayjs/core": "^4.0.0-beta.2",
31
+ "@midwayjs/express": "^4.0.0-beta.2",
32
+ "@midwayjs/faas": "^4.0.0-beta.2",
33
+ "@midwayjs/fc-starter": "^4.0.0-beta.2",
34
+ "@midwayjs/koa": "^4.0.0-beta.2",
35
+ "@midwayjs/mock": "^4.0.0-beta.2",
36
+ "@midwayjs/web": "^4.0.0-beta.2",
37
37
  "fs-extra": "11.2.0"
38
38
  },
39
- "gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
39
+ "gitHead": "53bfef4c5279da5f09025e4610bdbf64f94f60bd"
40
40
  }