@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.
@@ -11,5 +11,6 @@ exports.upload = {
11
11
  tmpdir: (0, path_1.join)((0, os_1.tmpdir)(), 'midway-upload-files'),
12
12
  cleanTimeout: 5 * 60 * 1000,
13
13
  base64: false,
14
+ allowFieldsDuplication: false,
14
15
  };
15
16
  //# sourceMappingURL=config.default.js.map
@@ -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;
@@ -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[head['content-disposition'].name] = data.toString();
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[head['content-disposition'].name] = data.toString();
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.5",
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.5",
32
+ "@midwayjs/koa": "^3.16.6",
33
33
  "@midwayjs/mock": "^3.16.5",
34
- "@midwayjs/web": "^3.16.5"
34
+ "@midwayjs/web": "^3.16.6"
35
35
  },
36
- "gitHead": "087b3a52b3ed510e098a731e5dd0d0647ea3b168"
36
+ "gitHead": "3daa965bdae6938d4228f1996777141983142890"
37
37
  }