@midwayjs/upload 3.19.0 → 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 +9 -13
- package/dist/parse.d.ts +2 -0
- package/dist/parse.js +2 -2
- package/dist/utils.js +3 -3
- package/package.json +10 -10
package/dist/configuration.js
CHANGED
|
@@ -33,6 +33,7 @@ let UploadConfiguration = class UploadConfiguration {
|
|
|
33
33
|
await (0, utils_1.stopAutoRemoveUploadTmpFile)();
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
+
exports.UploadConfiguration = UploadConfiguration;
|
|
36
37
|
__decorate([
|
|
37
38
|
(0, core_1.Inject)(),
|
|
38
39
|
__metadata("design:type", core_1.MidwayApplicationManager)
|
|
@@ -41,7 +42,7 @@ __decorate([
|
|
|
41
42
|
(0, core_1.Config)('upload'),
|
|
42
43
|
__metadata("design:type", Object)
|
|
43
44
|
], UploadConfiguration.prototype, "uploadConfig", void 0);
|
|
44
|
-
UploadConfiguration = __decorate([
|
|
45
|
+
exports.UploadConfiguration = UploadConfiguration = __decorate([
|
|
45
46
|
(0, core_1.Configuration)({
|
|
46
47
|
namespace: 'upload',
|
|
47
48
|
importConfigs: [
|
|
@@ -51,5 +52,4 @@ UploadConfiguration = __decorate([
|
|
|
51
52
|
],
|
|
52
53
|
})
|
|
53
54
|
], UploadConfiguration);
|
|
54
|
-
exports.UploadConfiguration = UploadConfiguration;
|
|
55
55
|
//# 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
|
@@ -54,21 +54,19 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
54
54
|
this.uploadFileMimeTypeMap.set(ext, mime);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
if (
|
|
57
|
+
if ('express' === app.getNamespace()) {
|
|
58
58
|
return async (req, res, next) => {
|
|
59
59
|
return this.execUpload(req, req, res, next, true);
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
63
|
return async (ctx, next) => {
|
|
64
|
-
|
|
65
|
-
const req = ((_a = ctx.request) === null || _a === void 0 ? void 0 : _a.req) || ctx.request;
|
|
64
|
+
const req = ctx.request?.req || ctx.request;
|
|
66
65
|
return this.execUpload(ctx, req, ctx, next, false);
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
async execUpload(ctx, req, res, next, isExpress) {
|
|
71
|
-
var _a;
|
|
72
70
|
const { mode, tmpdir, fileSize } = this.uploadConfig;
|
|
73
71
|
const boundary = this.getUploadBoundary(req);
|
|
74
72
|
if (!boundary) {
|
|
@@ -77,8 +75,7 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
77
75
|
ctx.fields = {};
|
|
78
76
|
ctx.files = [];
|
|
79
77
|
ctx.cleanupRequestFiles = async () => {
|
|
80
|
-
|
|
81
|
-
if (!((_a = ctx.files) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
78
|
+
if (!ctx.files?.length) {
|
|
82
79
|
return [];
|
|
83
80
|
}
|
|
84
81
|
return Promise.all(ctx.files.map(async (fileInfo) => {
|
|
@@ -89,7 +86,7 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
89
86
|
await unlink(fileInfo.data);
|
|
90
87
|
return true;
|
|
91
88
|
}
|
|
92
|
-
catch
|
|
89
|
+
catch {
|
|
93
90
|
return false;
|
|
94
91
|
}
|
|
95
92
|
}));
|
|
@@ -132,7 +129,7 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
132
129
|
limit: fileSize,
|
|
133
130
|
});
|
|
134
131
|
}
|
|
135
|
-
else if (
|
|
132
|
+
else if (req?.originEvent?.body &&
|
|
136
133
|
(typeof req.originEvent.body === 'string' ||
|
|
137
134
|
Buffer.isBuffer(req.originEvent.body))) {
|
|
138
135
|
body = req.originEvent.body;
|
|
@@ -179,7 +176,6 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
179
176
|
return next();
|
|
180
177
|
}
|
|
181
178
|
getUploadBoundary(request) {
|
|
182
|
-
var _a;
|
|
183
179
|
const method = (request.method || request.httpMethod || '').toUpperCase();
|
|
184
180
|
if (method !== 'POST' &&
|
|
185
181
|
method !== 'PUT' &&
|
|
@@ -187,7 +183,7 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
187
183
|
method !== 'PATCH') {
|
|
188
184
|
return false;
|
|
189
185
|
}
|
|
190
|
-
if (!
|
|
186
|
+
if (!request.headers?.['content-type']) {
|
|
191
187
|
return false;
|
|
192
188
|
}
|
|
193
189
|
const contentType = request.headers['content-type'];
|
|
@@ -195,7 +191,7 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
195
191
|
return false;
|
|
196
192
|
}
|
|
197
193
|
const boundaryMatch = /boundary=(.*)(;|\s|$)/.exec(contentType);
|
|
198
|
-
if (!
|
|
194
|
+
if (!boundaryMatch?.[1]) {
|
|
199
195
|
return false;
|
|
200
196
|
}
|
|
201
197
|
return boundaryMatch[1];
|
|
@@ -257,6 +253,7 @@ let UploadMiddleware = class UploadMiddleware {
|
|
|
257
253
|
return 'upload';
|
|
258
254
|
}
|
|
259
255
|
};
|
|
256
|
+
exports.UploadMiddleware = UploadMiddleware;
|
|
260
257
|
__decorate([
|
|
261
258
|
(0, core_1.Config)('upload'),
|
|
262
259
|
__metadata("design:type", Object)
|
|
@@ -271,8 +268,7 @@ __decorate([
|
|
|
271
268
|
__metadata("design:paramtypes", []),
|
|
272
269
|
__metadata("design:returntype", Promise)
|
|
273
270
|
], UploadMiddleware.prototype, "init", null);
|
|
274
|
-
UploadMiddleware = __decorate([
|
|
271
|
+
exports.UploadMiddleware = UploadMiddleware = __decorate([
|
|
275
272
|
(0, core_1.Middleware)()
|
|
276
273
|
], UploadMiddleware);
|
|
277
|
-
exports.UploadMiddleware = UploadMiddleware;
|
|
278
274
|
//# sourceMappingURL=middleware.js.map
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
2
4
|
import { Readable } from 'stream';
|
|
3
5
|
import { UploadFileInfo, UploadOptions } from './interface';
|
|
4
6
|
export declare const parseMultipart: (body: any, boundary: string, uploadConfig: UploadOptions) => Promise<{
|
package/dist/parse.js
CHANGED
|
@@ -183,7 +183,7 @@ const parseHead = (headBuf) => {
|
|
|
183
183
|
try {
|
|
184
184
|
return String.fromCharCode(parseInt(code));
|
|
185
185
|
}
|
|
186
|
-
catch
|
|
186
|
+
catch {
|
|
187
187
|
return origin;
|
|
188
188
|
}
|
|
189
189
|
})
|
|
@@ -192,7 +192,7 @@ const parseHead = (headBuf) => {
|
|
|
192
192
|
const headCol = {};
|
|
193
193
|
value.split(/;\s+/).forEach((kv) => {
|
|
194
194
|
const [k, v] = kv.split('=');
|
|
195
|
-
headCol[k] = v ? v.replace(/^"/, '').replace(/"$/, '') : v
|
|
195
|
+
headCol[k] = v ? v.replace(/^"/, '').replace(/"$/, '') : v ?? true;
|
|
196
196
|
});
|
|
197
197
|
head[name] = headCol;
|
|
198
198
|
}
|
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/upload",
|
|
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": [],
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"raw-body": "2.5.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@midwayjs/core": "^
|
|
30
|
-
"@midwayjs/express": "^
|
|
31
|
-
"@midwayjs/faas": "^
|
|
32
|
-
"@midwayjs/koa": "^
|
|
33
|
-
"@midwayjs/mock": "^
|
|
34
|
-
"@midwayjs/web": "^
|
|
29
|
+
"@midwayjs/core": "^4.0.0-alpha.1",
|
|
30
|
+
"@midwayjs/express": "^4.0.0-alpha.1",
|
|
31
|
+
"@midwayjs/faas": "^4.0.0-alpha.1",
|
|
32
|
+
"@midwayjs/koa": "^4.0.0-alpha.1",
|
|
33
|
+
"@midwayjs/mock": "^4.0.0-alpha.1",
|
|
34
|
+
"@midwayjs/web": "^4.0.0-alpha.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
|
|
37
37
|
}
|