@midwayjs/busboy 3.19.2 → 4.0.0-alpha.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/dist/configuration.js +2 -2
- package/dist/constants.js +5 -5
- package/dist/middleware.d.ts +1 -0
- package/dist/middleware.js +8 -12
- package/dist/parse.d.ts +1 -0
- package/dist/parse.js +2 -2
- package/dist/utils.js +3 -3
- package/package.json +12 -10
package/dist/configuration.js
CHANGED
|
@@ -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',
|
package/dist/middleware.d.ts
CHANGED
package/dist/middleware.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
101
|
+
catch {
|
|
104
102
|
return false;
|
|
105
103
|
}
|
|
106
104
|
}));
|
|
@@ -303,9 +301,8 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
303
301
|
ctxOrReq.files = files;
|
|
304
302
|
}
|
|
305
303
|
async processServerlessUpload(req, boundary, uploadConfig, next, currentContextWhiteListMap, currentContextMimeTypeWhiteListMap, ctxOrReq) {
|
|
306
|
-
var _a;
|
|
307
304
|
let body;
|
|
308
|
-
if (
|
|
305
|
+
if (req?.originEvent?.body &&
|
|
309
306
|
(typeof req.originEvent.body === 'string' ||
|
|
310
307
|
Buffer.isBuffer(req.originEvent.body))) {
|
|
311
308
|
body = req.originEvent.body;
|
|
@@ -408,7 +405,6 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
408
405
|
return false;
|
|
409
406
|
}
|
|
410
407
|
getUploadBoundary(request) {
|
|
411
|
-
var _a;
|
|
412
408
|
const method = (request.method || request.httpMethod || '').toUpperCase();
|
|
413
409
|
if (method !== 'POST' &&
|
|
414
410
|
method !== 'PUT' &&
|
|
@@ -416,7 +412,7 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
416
412
|
method !== 'PATCH') {
|
|
417
413
|
return false;
|
|
418
414
|
}
|
|
419
|
-
if (!
|
|
415
|
+
if (!request.headers?.['content-type']) {
|
|
420
416
|
return false;
|
|
421
417
|
}
|
|
422
418
|
const contentType = request.headers['content-type'];
|
|
@@ -424,12 +420,13 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
424
420
|
return false;
|
|
425
421
|
}
|
|
426
422
|
const boundaryMatch = /boundary=(.*)(;|\s|$)/.exec(contentType);
|
|
427
|
-
if (!
|
|
423
|
+
if (!boundaryMatch?.[1]) {
|
|
428
424
|
return false;
|
|
429
425
|
}
|
|
430
426
|
return boundaryMatch[1];
|
|
431
427
|
}
|
|
432
428
|
};
|
|
429
|
+
exports.UploadMiddleware = UploadMiddleware;
|
|
433
430
|
__decorate([
|
|
434
431
|
(0, core_1.Config)('busboy'),
|
|
435
432
|
__metadata("design:type", Object)
|
|
@@ -444,8 +441,7 @@ __decorate([
|
|
|
444
441
|
__metadata("design:paramtypes", []),
|
|
445
442
|
__metadata("design:returntype", Promise)
|
|
446
443
|
], UploadMiddleware.prototype, "init", null);
|
|
447
|
-
UploadMiddleware = __decorate([
|
|
444
|
+
exports.UploadMiddleware = UploadMiddleware = __decorate([
|
|
448
445
|
(0, core_1.Middleware)()
|
|
449
446
|
], UploadMiddleware);
|
|
450
|
-
exports.UploadMiddleware = UploadMiddleware;
|
|
451
447
|
//# sourceMappingURL=middleware.js.map
|
package/dist/parse.d.ts
CHANGED
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
+
"version": "4.0.0-alpha.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
|
|
10
|
-
"cov": "node
|
|
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": "^
|
|
31
|
-
"@midwayjs/express": "^
|
|
32
|
-
"@midwayjs/faas": "^
|
|
33
|
-
"@midwayjs/
|
|
34
|
-
"@midwayjs/
|
|
35
|
-
"@midwayjs/
|
|
30
|
+
"@midwayjs/core": "^4.0.0-alpha.1",
|
|
31
|
+
"@midwayjs/express": "^4.0.0-alpha.1",
|
|
32
|
+
"@midwayjs/faas": "^4.0.0-alpha.1",
|
|
33
|
+
"@midwayjs/fc-starter": "^4.0.0-alpha.1",
|
|
34
|
+
"@midwayjs/koa": "^4.0.0-alpha.1",
|
|
35
|
+
"@midwayjs/mock": "^4.0.0-alpha.1",
|
|
36
|
+
"@midwayjs/web": "^4.0.0-alpha.1",
|
|
37
|
+
"fs-extra": "11.2.0"
|
|
36
38
|
},
|
|
37
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
|
|
38
40
|
}
|