@midwayjs/busboy 3.20.2 → 3.20.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/dist/interface.d.ts +4 -0
- package/dist/middleware.js +22 -5
- package/package.json +8 -8
package/dist/interface.d.ts
CHANGED
|
@@ -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
|
/**
|
package/dist/middleware.js
CHANGED
|
@@ -121,7 +121,7 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
121
121
|
}
|
|
122
122
|
async processFileOrStream(req, uploadConfig, currentContextWhiteListMap, currentContextMimeTypeWhiteListMap, ctxOrReq) {
|
|
123
123
|
let isStreamResolve = false;
|
|
124
|
-
const { mode, tmpdir } = uploadConfig;
|
|
124
|
+
const { mode, tmpdir, allowFieldsDuplication } = uploadConfig;
|
|
125
125
|
const { files = [], fields = [] } = await new Promise((resolveP, reject) => {
|
|
126
126
|
const bb = busboy({
|
|
127
127
|
headers: req.headers,
|
|
@@ -221,10 +221,27 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
221
221
|
req.pipe(bb);
|
|
222
222
|
});
|
|
223
223
|
ctxOrReq.files = files;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
if (allowFieldsDuplication) {
|
|
225
|
+
// 如果重复,则使用数组
|
|
226
|
+
ctxOrReq.fields = fields.reduce((accumulator, current) => {
|
|
227
|
+
if (accumulator[current.name]) {
|
|
228
|
+
if (!Array.isArray(accumulator[current.name])) {
|
|
229
|
+
accumulator[current.name] = [accumulator[current.name]];
|
|
230
|
+
}
|
|
231
|
+
accumulator[current.name].push(current.value);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
accumulator[current.name] = current.value;
|
|
235
|
+
}
|
|
236
|
+
return accumulator;
|
|
237
|
+
}, {});
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
ctxOrReq.fields = fields.reduce((accumulator, current) => {
|
|
241
|
+
accumulator[current.name] = current.value;
|
|
242
|
+
return accumulator;
|
|
243
|
+
}, {});
|
|
244
|
+
}
|
|
228
245
|
}
|
|
229
246
|
async processAsyncIterator(req, uploadConfig, currentContextWhiteListMap, currentContextMimeTypeWhiteListMap, ctxOrReq) {
|
|
230
247
|
const bb = busboy({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/busboy",
|
|
3
|
-
"version": "3.20.
|
|
3
|
+
"version": "3.20.3",
|
|
4
4
|
"description": "Midway Component for upload",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"file-type": "16.5.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@midwayjs/core": "^3.20.
|
|
31
|
-
"@midwayjs/express": "^3.20.
|
|
32
|
-
"@midwayjs/faas": "^3.20.
|
|
33
|
-
"@midwayjs/koa": "^3.20.
|
|
34
|
-
"@midwayjs/mock": "^3.20.
|
|
35
|
-
"@midwayjs/web": "^3.20.
|
|
30
|
+
"@midwayjs/core": "^3.20.3",
|
|
31
|
+
"@midwayjs/express": "^3.20.3",
|
|
32
|
+
"@midwayjs/faas": "^3.20.3",
|
|
33
|
+
"@midwayjs/koa": "^3.20.3",
|
|
34
|
+
"@midwayjs/mock": "^3.20.3",
|
|
35
|
+
"@midwayjs/web": "^3.20.3"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a0918e46838e220fd000997796dbc8d669d28746"
|
|
38
38
|
}
|