Files
docmost-ryan/server/src/core/attachment/attachment.interceptor.ts
2024-01-08 09:56:10 +01:00

26 lines
601 B
TypeScript

import {
Injectable,
NestInterceptor,
ExecutionContext,
CallHandler,
BadRequestException,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { FastifyRequest } from 'fastify';
@Injectable()
export class AttachmentInterceptor implements NestInterceptor {
public intercept(
context: ExecutionContext,
next: CallHandler,
): Observable<any> {
const req: FastifyRequest = context.switchToHttp().getRequest();
if (!req.isMultipart() || !req.file) {
throw new BadRequestException('Invalid multipart content type');
}
return next.handle();
}
}