UNPKG

@aprilnea/nest-file-fastify

Version:

fastify-multipart decorators for Nest.js

27 lines 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileInterceptor = void 0; const rxjs_1 = require("rxjs"); const common_1 = require("@nestjs/common"); const request_1 = require("../multipart/request"); const options_1 = require("../multipart/options"); const single_file_1 = require("../multipart/handlers/single-file"); function FileInterceptor(fieldName, options) { class MixinInterceptor { constructor() { this.options = (0, options_1.transformUploadOptions)(options); } async intercept(context, next) { const ctx = context.switchToHttp(); const req = (0, request_1.getMultipartRequest)(ctx); const { file, body, remove } = await (0, single_file_1.handleMultipartSingleFile)(req, fieldName, this.options); req.body = body; req.storageFile = file; return next.handle().pipe((0, rxjs_1.tap)(remove)); } } const Interceptor = (0, common_1.mixin)(MixinInterceptor); return Interceptor; } exports.FileInterceptor = FileInterceptor; //# sourceMappingURL=file-interceptor.js.map