@tsed/common 6.107.0 → 6.107.3
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/lib/cjs/middlewares/PlatformMulterMiddleware.js +13 -2
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/esm/middlewares/PlatformMulterMiddleware.js +12 -2
- package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +5 -0
- package/package.json +16 -16
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var PlatformMulterMiddleware_1;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.PlatformMulterMiddleware = void 0;
|
|
4
|
+
exports.PlatformMulterMiddleware = exports.MulterException = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const di_1 = require("@tsed/di");
|
|
7
7
|
const exceptions_1 = require("@tsed/exceptions");
|
|
8
8
|
const platform_middlewares_1 = require("@tsed/platform-middlewares");
|
|
9
9
|
const platform_params_1 = require("@tsed/platform-params");
|
|
10
10
|
const PlatformApplication_1 = require("../services/PlatformApplication");
|
|
11
|
+
class MulterException extends exceptions_1.BadRequest {
|
|
12
|
+
constructor(er) {
|
|
13
|
+
super(er.message);
|
|
14
|
+
this.origin = er;
|
|
15
|
+
this.name = er.code;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.MulterException = MulterException;
|
|
11
19
|
/**
|
|
12
20
|
* @middleware
|
|
13
21
|
*/
|
|
@@ -27,7 +35,10 @@ let PlatformMulterMiddleware = PlatformMulterMiddleware_1 = class PlatformMulter
|
|
|
27
35
|
return await middleware(ctx.getRequest(), ctx.getResponse());
|
|
28
36
|
}
|
|
29
37
|
catch (er) {
|
|
30
|
-
|
|
38
|
+
if (er.code) {
|
|
39
|
+
throw new MulterException(er);
|
|
40
|
+
}
|
|
41
|
+
throw er;
|
|
31
42
|
}
|
|
32
43
|
}
|
|
33
44
|
getFields(conf) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformMulterMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformMulterMiddleware.ts"],"names":[],"mappings":";;;;;AAAA,iCAA0C;AAC1C,
|
|
1
|
+
{"version":3,"file":"PlatformMulterMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformMulterMiddleware.ts"],"names":[],"mappings":";;;;;AAAA,iCAA0C;AAC1C,iDAA4C;AAC5C,qEAAyE;AACzE,2DAA8C;AAE9C,yEAAoE;AAOpE,MAAa,eAAgB,SAAQ,uBAAU;IAC7C,YAAY,EAAe;QACzB,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;IACtB,CAAC;CACF;AAND,0CAMC;AAED;;GAEG;AAEH,IAAa,wBAAwB,gCAArC,MAAa,wBAAwB;IAOnC,KAAK,CAAC,GAAG,CAAY,GAAY;QAC/B,IAAI;YACF,MAAM,EAAC,MAAM,EAAE,OAAO,GAAG,EAAE,EAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,0BAAwB,CAAC,CAAC;YAC1E,MAAM,QAAQ,GAA2B;gBACvC,GAAG,IAAI,CAAC,QAAQ;gBAChB,GAAG,OAAO;aACX,CAAC;YAEF,0BAA0B;YAC1B,IAAI,QAAQ,CAAC,OAAO,EAAE;gBACpB,OAAO,QAAQ,CAAC,IAAI,CAAC;aACtB;YAED,MAAM,UAAU,GAAQ,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC,CAAC;YAEnF,OAAO,MAAM,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;SAC9D;QAAC,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,CAAC,IAAI,EAAE;gBACX,MAAM,IAAI,eAAe,CAAC,EAAE,CAAC,CAAC;aAC/B;YAED,MAAM,EAAE,CAAC;SACV;IACH,CAAC;IAES,SAAS,CAAC,IAAwB;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAC,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC,CAAC,CAAC;IACnE,CAAC;CACF,CAAA;AAjCC;IADC,IAAA,aAAQ,EAAC,QAAQ,EAAE,EAAE,CAAC;;0DACU;AAGjC;IADC,IAAA,WAAM,GAAE;2CACJ,yCAAmB;qDAAC;AAEzB;IAAW,wBAAA,IAAA,yBAAO,GAAE,CAAA;;;;mDAuBnB;AA9BU,wBAAwB;IADpC,IAAA,iCAAU,GAAE;GACA,wBAAwB,CAmCpC;AAnCY,4DAAwB","sourcesContent":["import {Constant, Inject} from \"@tsed/di\";\nimport {BadRequest} from \"@tsed/exceptions\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\nimport {PlatformMulterField, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport type {MulterError} from \"multer\";\n\nexport interface MulterInputOptions {\n fields: PlatformMulterField[];\n}\n\nexport class MulterException extends BadRequest {\n constructor(er: MulterError) {\n super(er.message);\n this.origin = er;\n this.name = er.code;\n }\n}\n\n/**\n * @middleware\n */\n@Middleware()\nexport class PlatformMulterMiddleware implements MiddlewareMethods {\n @Constant(\"multer\", {})\n settings: PlatformMulterSettings;\n\n @Inject()\n app: PlatformApplication;\n\n async use(@Context() ctx: Context) {\n try {\n const {fields, options = {}} = ctx.endpoint.get(PlatformMulterMiddleware);\n const settings: PlatformMulterSettings = {\n ...this.settings,\n ...options\n };\n\n /* istanbul ignore next */\n if (settings.storage) {\n delete settings.dest;\n }\n\n const middleware: any = this.app.multer(settings).fields(this.getFields({fields}));\n\n return await middleware(ctx.getRequest(), ctx.getResponse());\n } catch (er) {\n if (er.code) {\n throw new MulterException(er);\n }\n\n throw er;\n }\n }\n\n protected getFields(conf: MulterInputOptions) {\n return conf.fields.map(({name, maxCount}) => ({name, maxCount}));\n }\n}\n"]}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
var PlatformMulterMiddleware_1;
|
|
2
2
|
import { __decorate, __metadata, __param } from "tslib";
|
|
3
3
|
import { Constant, Inject } from "@tsed/di";
|
|
4
|
-
import {
|
|
4
|
+
import { BadRequest } from "@tsed/exceptions";
|
|
5
5
|
import { Middleware } from "@tsed/platform-middlewares";
|
|
6
6
|
import { Context } from "@tsed/platform-params";
|
|
7
7
|
import { PlatformApplication } from "../services/PlatformApplication.js";
|
|
8
|
+
export class MulterException extends BadRequest {
|
|
9
|
+
constructor(er) {
|
|
10
|
+
super(er.message);
|
|
11
|
+
this.origin = er;
|
|
12
|
+
this.name = er.code;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
8
15
|
/**
|
|
9
16
|
* @middleware
|
|
10
17
|
*/
|
|
@@ -24,7 +31,10 @@ let PlatformMulterMiddleware = PlatformMulterMiddleware_1 = class PlatformMulter
|
|
|
24
31
|
return await middleware(ctx.getRequest(), ctx.getResponse());
|
|
25
32
|
}
|
|
26
33
|
catch (er) {
|
|
27
|
-
|
|
34
|
+
if (er.code) {
|
|
35
|
+
throw new MulterException(er);
|
|
36
|
+
}
|
|
37
|
+
throw er;
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
getFields(conf) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformMulterMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformMulterMiddleware.ts"],"names":[],"mappings":";;AA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AC;YAEnF,OAAO,MAAM,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;SAC9D;QAAC,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,CAAC,IAAI,EAAE;gBACX,MAAM,IAAI,eAAe,CAAC,EAAE,CAAC,CAAC;aAC/B;YAED,MAAM,EAAE,CAAC;SACV;IACH,CAAC;IAES,SAAS,CAAC,IAAwB;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAC,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC,CAAC,CAAC;IACnE,CAAC;CACF,CAAA;AAjCC;IADC,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC;;0DACU;AAGjC;IADC,MAAM,EAAE;8BACJ,mBAAmB;qDAAC;AAEzB;IAAW,WAAA,OAAO,EAAE,CAAA;;;;mDAuBnB;AA9BU,wBAAwB;IADpC,UAAU,EAAE;GACA,wBAAwB,CAmCpC;SAnCY,wBAAwB","sourcesContent":["import {Constant, Inject} from \"@tsed/di\";\nimport {BadRequest} from \"@tsed/exceptions\";\nimport {Middleware, MiddlewareMethods} from \"@tsed/platform-middlewares\";\nimport {Context} from \"@tsed/platform-params\";\nimport {PlatformMulterField, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport type {MulterError} from \"multer\";\n\nexport interface MulterInputOptions {\n fields: PlatformMulterField[];\n}\n\nexport class MulterException extends BadRequest {\n constructor(er: MulterError) {\n super(er.message);\n this.origin = er;\n this.name = er.code;\n }\n}\n\n/**\n * @middleware\n */\n@Middleware()\nexport class PlatformMulterMiddleware implements MiddlewareMethods {\n @Constant(\"multer\", {})\n settings: PlatformMulterSettings;\n\n @Inject()\n app: PlatformApplication;\n\n async use(@Context() ctx: Context) {\n try {\n const {fields, options = {}} = ctx.endpoint.get(PlatformMulterMiddleware);\n const settings: PlatformMulterSettings = {\n ...this.settings,\n ...options\n };\n\n /* istanbul ignore next */\n if (settings.storage) {\n delete settings.dest;\n }\n\n const middleware: any = this.app.multer(settings).fields(this.getFields({fields}));\n\n return await middleware(ctx.getRequest(), ctx.getResponse());\n } catch (er) {\n if (er.code) {\n throw new MulterException(er);\n }\n\n throw er;\n }\n }\n\n protected getFields(conf: MulterInputOptions) {\n return conf.fields.map(({name, maxCount}) => ({name, maxCount}));\n }\n}\n"]}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { BadRequest } from "@tsed/exceptions";
|
|
1
2
|
import { MiddlewareMethods } from "@tsed/platform-middlewares";
|
|
2
3
|
import { Context } from "@tsed/platform-params";
|
|
3
4
|
import { PlatformMulterField, PlatformMulterSettings } from "../config/interfaces/PlatformMulterSettings";
|
|
4
5
|
import { PlatformApplication } from "../services/PlatformApplication";
|
|
6
|
+
import type { MulterError } from "multer";
|
|
5
7
|
export interface MulterInputOptions {
|
|
6
8
|
fields: PlatformMulterField[];
|
|
7
9
|
}
|
|
10
|
+
export declare class MulterException extends BadRequest {
|
|
11
|
+
constructor(er: MulterError);
|
|
12
|
+
}
|
|
8
13
|
/**
|
|
9
14
|
* @middleware
|
|
10
15
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/common",
|
|
3
|
-
"version": "6.107.
|
|
3
|
+
"version": "6.107.3",
|
|
4
4
|
"description": "A TypeScript Framework on top of Express",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -61,21 +61,21 @@
|
|
|
61
61
|
}
|
|
62
62
|
],
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@tsed/components-scan": "6.107.
|
|
65
|
-
"@tsed/core": "6.107.
|
|
66
|
-
"@tsed/exceptions": "6.107.
|
|
67
|
-
"@tsed/json-mapper": "6.107.
|
|
64
|
+
"@tsed/components-scan": "6.107.3",
|
|
65
|
+
"@tsed/core": "6.107.3",
|
|
66
|
+
"@tsed/exceptions": "6.107.3",
|
|
67
|
+
"@tsed/json-mapper": "6.107.3",
|
|
68
68
|
"@tsed/logger": ">=6.1.0",
|
|
69
69
|
"@tsed/logger-file": ">=6.1.0",
|
|
70
|
-
"@tsed/perf": "6.107.
|
|
71
|
-
"@tsed/platform-cache": "6.107.
|
|
72
|
-
"@tsed/platform-exceptions": "6.107.
|
|
73
|
-
"@tsed/platform-log-middleware": "6.107.
|
|
74
|
-
"@tsed/platform-middlewares": "6.107.
|
|
75
|
-
"@tsed/platform-params": "6.107.
|
|
76
|
-
"@tsed/platform-response-filter": "6.107.
|
|
77
|
-
"@tsed/platform-views": "6.107.
|
|
78
|
-
"@tsed/schema": "6.107.
|
|
70
|
+
"@tsed/perf": "6.107.3",
|
|
71
|
+
"@tsed/platform-cache": "6.107.3",
|
|
72
|
+
"@tsed/platform-exceptions": "6.107.3",
|
|
73
|
+
"@tsed/platform-log-middleware": "6.107.3",
|
|
74
|
+
"@tsed/platform-middlewares": "6.107.3",
|
|
75
|
+
"@tsed/platform-params": "6.107.3",
|
|
76
|
+
"@tsed/platform-response-filter": "6.107.3",
|
|
77
|
+
"@tsed/platform-views": "6.107.3",
|
|
78
|
+
"@tsed/schema": "6.107.3",
|
|
79
79
|
"@types/json-schema": "7.0.7",
|
|
80
80
|
"@types/on-finished": "2.3.1",
|
|
81
81
|
"on-finished": "2.3.0",
|
|
@@ -83,10 +83,10 @@
|
|
|
83
83
|
"uuid": "8.3.2"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@tsed/core": "6.107.
|
|
86
|
+
"@tsed/core": "6.107.3"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
|
-
"@tsed/di": "^6.107.
|
|
89
|
+
"@tsed/di": "^6.107.3",
|
|
90
90
|
"@tsed/logger": ">=6.1.0",
|
|
91
91
|
"@tsed/logger-file": ">=6.1.0"
|
|
92
92
|
}
|