@midwayjs/busboy 3.20.5 → 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.
@@ -31,6 +31,7 @@ let BusboyConfiguration = class BusboyConfiguration {
31
31
  await (0, utils_1.stopAutoRemoveUploadTmpFile)();
32
32
  }
33
33
  };
34
+ exports.BusboyConfiguration = BusboyConfiguration;
34
35
  __decorate([
35
36
  (0, core_1.Config)('busboy'),
36
37
  __metadata("design:type", Object)
@@ -39,7 +40,7 @@ __decorate([
39
40
  (0, core_1.Logger)('coreLogger'),
40
41
  __metadata("design:type", Object)
41
42
  ], BusboyConfiguration.prototype, "logger", void 0);
42
- BusboyConfiguration = __decorate([
43
+ exports.BusboyConfiguration = BusboyConfiguration = __decorate([
43
44
  (0, core_1.Configuration)({
44
45
  namespace: 'busboy',
45
46
  importConfigs: [
@@ -57,5 +58,4 @@ BusboyConfiguration = __decorate([
57
58
  ],
58
59
  })
59
60
  ], BusboyConfiguration);
60
- exports.BusboyConfiguration = BusboyConfiguration;
61
61
  //# sourceMappingURL=configuration.js.map
package/dist/constants.js CHANGED
@@ -4,11 +4,11 @@ exports.EXT_KEY = exports.DefaultUploadFileMimeType = exports.uploadWhiteList =
4
4
  exports.uploadWhiteList = [
5
5
  // images
6
6
  '.jpg',
7
- '.jpeg',
8
- '.png',
9
- '.gif',
10
- '.bmp',
11
- '.wbmp',
7
+ '.jpeg', // image/jpeg
8
+ '.png', // image/png, image/x-png
9
+ '.gif', // image/gif
10
+ '.bmp', // image/bmp
11
+ '.wbmp', // image/vnd.wap.wbmp
12
12
  '.webp',
13
13
  '.tif',
14
14
  '.tiff',
@@ -60,8 +60,7 @@ let UploadMiddleware = class UploadMiddleware {
60
60
  ? (0, core_1.extend)({}, this.uploadConfig, options || {})
61
61
  : this.uploadConfig;
62
62
  return async (ctxOrReq, resOrNext, next) => {
63
- var _a;
64
- const req = ((_a = ctxOrReq.request) === null || _a === void 0 ? void 0 : _a.req) || ctxOrReq.request || ctxOrReq;
63
+ const req = ctxOrReq.request?.req || ctxOrReq.request || ctxOrReq;
65
64
  next = isExpress ? next : resOrNext;
66
65
  const boundary = this.getUploadBoundary(req);
67
66
  if (!boundary) {
@@ -88,8 +87,7 @@ let UploadMiddleware = class UploadMiddleware {
88
87
  }
89
88
  }
90
89
  ctxOrReq.cleanupRequestFiles = async () => {
91
- var _a;
92
- if (!((_a = ctxOrReq.files) === null || _a === void 0 ? void 0 : _a.length)) {
90
+ if (!ctxOrReq.files?.length) {
93
91
  return [];
94
92
  }
95
93
  return Promise.all(ctxOrReq.files.map(async (fileInfo) => {
@@ -100,7 +98,7 @@ let UploadMiddleware = class UploadMiddleware {
100
98
  await unlink(fileInfo.data);
101
99
  return true;
102
100
  }
103
- catch (_a) {
101
+ catch {
104
102
  return false;
105
103
  }
106
104
  }));
@@ -320,9 +318,8 @@ let UploadMiddleware = class UploadMiddleware {
320
318
  ctxOrReq.files = files;
321
319
  }
322
320
  async processServerlessUpload(req, boundary, uploadConfig, next, currentContextWhiteListMap, currentContextMimeTypeWhiteListMap, ctxOrReq) {
323
- var _a;
324
321
  let body;
325
- if (((_a = req === null || req === void 0 ? void 0 : req.originEvent) === null || _a === void 0 ? void 0 : _a.body) &&
322
+ if (req?.originEvent?.body &&
326
323
  (typeof req.originEvent.body === 'string' ||
327
324
  Buffer.isBuffer(req.originEvent.body))) {
328
325
  body = req.originEvent.body;
@@ -425,7 +422,6 @@ let UploadMiddleware = class UploadMiddleware {
425
422
  return false;
426
423
  }
427
424
  getUploadBoundary(request) {
428
- var _a;
429
425
  const method = (request.method || request.httpMethod || '').toUpperCase();
430
426
  if (method !== 'POST' &&
431
427
  method !== 'PUT' &&
@@ -433,7 +429,7 @@ let UploadMiddleware = class UploadMiddleware {
433
429
  method !== 'PATCH') {
434
430
  return false;
435
431
  }
436
- if (!((_a = request.headers) === null || _a === void 0 ? void 0 : _a['content-type'])) {
432
+ if (!request.headers?.['content-type']) {
437
433
  return false;
438
434
  }
439
435
  const contentType = request.headers['content-type'];
@@ -441,12 +437,13 @@ let UploadMiddleware = class UploadMiddleware {
441
437
  return false;
442
438
  }
443
439
  const boundaryMatch = /boundary=(.*)(;|\s|$)/.exec(contentType);
444
- if (!(boundaryMatch === null || boundaryMatch === void 0 ? void 0 : boundaryMatch[1])) {
440
+ if (!boundaryMatch?.[1]) {
445
441
  return false;
446
442
  }
447
443
  return boundaryMatch[1];
448
444
  }
449
445
  };
446
+ exports.UploadMiddleware = UploadMiddleware;
450
447
  __decorate([
451
448
  (0, core_1.Config)('busboy'),
452
449
  __metadata("design:type", Object)
@@ -461,8 +458,7 @@ __decorate([
461
458
  __metadata("design:paramtypes", []),
462
459
  __metadata("design:returntype", Promise)
463
460
  ], UploadMiddleware.prototype, "init", null);
464
- UploadMiddleware = __decorate([
461
+ exports.UploadMiddleware = UploadMiddleware = __decorate([
465
462
  (0, core_1.Middleware)()
466
463
  ], UploadMiddleware);
467
- exports.UploadMiddleware = UploadMiddleware;
468
464
  //# sourceMappingURL=middleware.js.map
package/dist/parse.js CHANGED
@@ -76,7 +76,7 @@ const parseHead = (headBuf) => {
76
76
  try {
77
77
  return String.fromCharCode(parseInt(code));
78
78
  }
79
- catch (_a) {
79
+ catch {
80
80
  return origin;
81
81
  }
82
82
  })
@@ -85,7 +85,7 @@ const parseHead = (headBuf) => {
85
85
  const headCol = {};
86
86
  value.split(/;\s+/).forEach((kv) => {
87
87
  const [k, v] = kv.split('=');
88
- headCol[k] = v ? v.replace(/^"/, '').replace(/"$/, '') : v !== null && v !== void 0 ? v : true;
88
+ headCol[k] = v ? v.replace(/^"/, '').replace(/"$/, '') : v ?? true;
89
89
  });
90
90
  head[name] = headCol;
91
91
  }
package/dist/utils.js CHANGED
@@ -25,7 +25,7 @@ const autoRemoveUploadTmpFile = async (tmpDir, cleanTimeout) => {
25
25
  await unlink(filePath);
26
26
  }
27
27
  }
28
- catch (_a) {
28
+ catch {
29
29
  return false;
30
30
  }
31
31
  }));
@@ -49,7 +49,7 @@ const checkExists = async (path) => {
49
49
  await access(path, fs_1.constants.W_OK | fs_1.constants.R_OK);
50
50
  return true;
51
51
  }
52
- catch (_a) {
52
+ catch {
53
53
  return false;
54
54
  }
55
55
  };
@@ -63,7 +63,7 @@ const ensureDir = async (dirPath) => {
63
63
  await mkdir(dirPath, { recursive: true });
64
64
  return true;
65
65
  }
66
- catch (_a) {
66
+ catch {
67
67
  return false;
68
68
  }
69
69
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@midwayjs/busboy",
3
- "version": "3.20.5",
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",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
10
- "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
9
+ "test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
10
+ "cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
11
11
  "ci": "npm run test"
12
12
  },
13
13
  "keywords": [],
@@ -27,12 +27,14 @@
27
27
  "file-type": "16.5.4"
28
28
  },
29
29
  "devDependencies": {
30
- "@midwayjs/core": "^3.20.4",
31
- "@midwayjs/express": "^3.20.4",
32
- "@midwayjs/faas": "^3.20.4",
33
- "@midwayjs/koa": "^3.20.5",
34
- "@midwayjs/mock": "^3.20.4",
35
- "@midwayjs/web": "^3.20.4"
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
+ "fs-extra": "11.2.0"
36
38
  },
37
- "gitHead": "7ce57281bd3ef5d18dc50b47ff9bffb8a27c071e"
39
+ "gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
38
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.