@midwayjs/upload 3.16.5 → 3.16.7
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/config/config.default.js +1 -0
- package/dist/interface.d.ts +4 -0
- package/dist/middleware.js +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +19 -3
- package/package.json +4 -4
package/dist/interface.d.ts
CHANGED
|
@@ -39,6 +39,10 @@ export interface UploadOptions {
|
|
|
39
39
|
* Mime type white list
|
|
40
40
|
*/
|
|
41
41
|
mimeTypeWhiteList?: Record<string, string | string[]> | ((ctx: IMidwayContext<any>) => string | string[]);
|
|
42
|
+
/**
|
|
43
|
+
* Whether to allow fields duplication, default is `false`
|
|
44
|
+
*/
|
|
45
|
+
allowFieldsDuplication?: boolean;
|
|
42
46
|
}
|
|
43
47
|
export interface UploadFileInfo<T> {
|
|
44
48
|
filename: string;
|
package/dist/middleware.js
CHANGED
|
@@ -116,7 +116,7 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
116
116
|
let body;
|
|
117
117
|
if (this.isReadableStream(req, isExpress)) {
|
|
118
118
|
if (mode === 'stream') {
|
|
119
|
-
const { fields, fileInfo } = await (0, parse_1.parseFromReadableStream)(req, boundary);
|
|
119
|
+
const { fields, fileInfo } = await (0, parse_1.parseFromReadableStream)(req, boundary, this.uploadConfig);
|
|
120
120
|
const ext = this.checkAndGetExt(fileInfo.filename, currentContextWhiteListMap);
|
|
121
121
|
if (!ext) {
|
|
122
122
|
throw new _1.MultipartInvalidFilenameError(fileInfo.filename);
|
package/dist/parse.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const parseMultipart: (body: any, boundary: string, uploadConfig:
|
|
|
5
5
|
files: any[];
|
|
6
6
|
fields: {};
|
|
7
7
|
}>;
|
|
8
|
-
export declare const parseFromReadableStream: (readStream: Readable, boundary: any) => Promise<{
|
|
8
|
+
export declare const parseFromReadableStream: (readStream: Readable, boundary: any, uploadConfig: UploadOptions) => Promise<{
|
|
9
9
|
fields: any;
|
|
10
10
|
fileInfo: UploadFileInfo<Readable>;
|
|
11
11
|
}>;
|
package/dist/parse.js
CHANGED
|
@@ -3,6 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseHead = exports.bufferSplit = exports.bufferIndexOf = exports.parseFromReadableStream = exports.parseMultipart = void 0;
|
|
4
4
|
const stream_1 = require("stream");
|
|
5
5
|
const headSeparator = Buffer.from('\r\n\r\n');
|
|
6
|
+
function saveFields(fields, key, value, allowFieldsDuplication) {
|
|
7
|
+
if (allowFieldsDuplication) {
|
|
8
|
+
if (!fields[key]) {
|
|
9
|
+
fields[key] = value;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
if (!Array.isArray(fields[key])) {
|
|
13
|
+
fields[key] = [fields[key]];
|
|
14
|
+
}
|
|
15
|
+
fields[key].push(value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
fields[key] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
6
22
|
const parseMultipart = async (body, boundary, uploadConfig) => {
|
|
7
23
|
if (typeof body === 'string') {
|
|
8
24
|
if (uploadConfig.base64) {
|
|
@@ -23,7 +39,7 @@ const parseMultipart = async (body, boundary, uploadConfig) => {
|
|
|
23
39
|
}
|
|
24
40
|
if (!head['content-disposition'].filename) {
|
|
25
41
|
if (head['content-disposition'].name) {
|
|
26
|
-
fields
|
|
42
|
+
saveFields(fields, head['content-disposition'].name, data.toString(), uploadConfig.allowFieldsDuplication);
|
|
27
43
|
}
|
|
28
44
|
return;
|
|
29
45
|
}
|
|
@@ -41,7 +57,7 @@ const parseMultipart = async (body, boundary, uploadConfig) => {
|
|
|
41
57
|
};
|
|
42
58
|
exports.parseMultipart = parseMultipart;
|
|
43
59
|
const pre = Buffer.from('\r\n');
|
|
44
|
-
const parseFromReadableStream = (readStream, boundary) => {
|
|
60
|
+
const parseFromReadableStream = (readStream, boundary, uploadConfig) => {
|
|
45
61
|
const bufferSeparator = Buffer.from(`\r\n--${boundary}`);
|
|
46
62
|
const fields = {};
|
|
47
63
|
const fileInfo = {
|
|
@@ -100,7 +116,7 @@ const parseFromReadableStream = (readStream, boundary) => {
|
|
|
100
116
|
}
|
|
101
117
|
if (!head['content-disposition'].filename) {
|
|
102
118
|
if (head['content-disposition'].name) {
|
|
103
|
-
fields
|
|
119
|
+
saveFields(fields, head['content-disposition'].name, data.toString(), uploadConfig.allowFieldsDuplication);
|
|
104
120
|
}
|
|
105
121
|
continue;
|
|
106
122
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/upload",
|
|
3
|
-
"version": "3.16.
|
|
3
|
+
"version": "3.16.7",
|
|
4
4
|
"description": "Midway Component for upload",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"@midwayjs/core": "^3.16.2",
|
|
30
30
|
"@midwayjs/express": "^3.16.5",
|
|
31
31
|
"@midwayjs/faas": "^3.16.5",
|
|
32
|
-
"@midwayjs/koa": "^3.16.
|
|
32
|
+
"@midwayjs/koa": "^3.16.6",
|
|
33
33
|
"@midwayjs/mock": "^3.16.5",
|
|
34
|
-
"@midwayjs/web": "^3.16.
|
|
34
|
+
"@midwayjs/web": "^3.16.6"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "3daa965bdae6938d4228f1996777141983142890"
|
|
37
37
|
}
|