@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 +1 -1
- package/dist/interface.d.ts +4 -0
- package/dist/middleware.js +22 -5
- package/package.json +10 -10
package/README.md
CHANGED
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
|
@@ -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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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-
|
|
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": ">=
|
|
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-
|
|
31
|
-
"@midwayjs/express": "^4.0.0-
|
|
32
|
-
"@midwayjs/faas": "^4.0.0-
|
|
33
|
-
"@midwayjs/fc-starter": "^4.0.0-
|
|
34
|
-
"@midwayjs/koa": "^4.0.0-
|
|
35
|
-
"@midwayjs/mock": "^4.0.0-
|
|
36
|
-
"@midwayjs/web": "^4.0.0-
|
|
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": "
|
|
39
|
+
"gitHead": "53bfef4c5279da5f09025e4610bdbf64f94f60bd"
|
|
40
40
|
}
|