1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.FileInterceptor = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const common_1 = require("@nestjs/common");
|
6 | const multer = require("multer");
|
7 | const files_constants_1 = require("../files.constants");
|
8 | const multer_utils_1 = require("../multer/multer.utils");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function FileInterceptor(fieldName, localOptions) {
|
16 | let MixinInterceptor = class MixinInterceptor {
|
17 | constructor(options = {}) {
|
18 | this.multer = multer({
|
19 | ...options,
|
20 | ...localOptions,
|
21 | });
|
22 | }
|
23 | async intercept(context, next) {
|
24 | const ctx = context.switchToHttp();
|
25 | await new Promise((resolve, reject) => this.multer.single(fieldName)(ctx.getRequest(), ctx.getResponse(), (err) => {
|
26 | if (err) {
|
27 | const error = (0, multer_utils_1.transformException)(err);
|
28 | return reject(error);
|
29 | }
|
30 | resolve();
|
31 | }));
|
32 | return next.handle();
|
33 | }
|
34 | };
|
35 | MixinInterceptor = tslib_1.__decorate([
|
36 | tslib_1.__param(0, (0, common_1.Optional)()),
|
37 | tslib_1.__param(0, (0, common_1.Inject)(files_constants_1.MULTER_MODULE_OPTIONS)),
|
38 | tslib_1.__metadata("design:paramtypes", [Object])
|
39 | ], MixinInterceptor);
|
40 | const Interceptor = (0, common_1.mixin)(MixinInterceptor);
|
41 | return Interceptor;
|
42 | }
|
43 | exports.FileInterceptor = FileInterceptor;
|