@midwayjs/busboy 4.0.0-alpha.1 → 4.0.0-beta.1
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 +9 -9
- package/LICENSE +0 -21
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.1",
|
|
4
4
|
"description": "Midway Component for upload",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -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.1",
|
|
31
|
+
"@midwayjs/express": "^4.0.0-beta.1",
|
|
32
|
+
"@midwayjs/faas": "^4.0.0-beta.1",
|
|
33
|
+
"@midwayjs/fc-starter": "^4.0.0-beta.1",
|
|
34
|
+
"@midwayjs/koa": "^4.0.0-beta.1",
|
|
35
|
+
"@midwayjs/mock": "^4.0.0-beta.1",
|
|
36
|
+
"@midwayjs/web": "^4.0.0-beta.1",
|
|
37
37
|
"fs-extra": "11.2.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
|
|
40
40
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2013 - Now midwayjs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|