Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fileSizeLimit = (maxBytes: number | undefined) => (data: FileIncomingData) => (finish$: Observable) =>
fromEvent(data.file, 'limit').pipe(
takeUntil(finish$),
mergeMapTo(throwError(
new HttpError(`Reached file size limit for "${data.fieldname}" [${maxBytes} bytes]`, HttpStatus.PRECONDITION_FAILED),
)),
ignoreElements(),
);
mergeMap(() => throwError(
new HttpError(`Reached max fields count limit [${opts.maxFieldCount}]`, HttpStatus.PRECONDITION_FAILED),
)),
);
mergeMap(() => throwError(
new HttpError(`Reached max files count limit [${opts.maxFileCount}]`, HttpStatus.PRECONDITION_FAILED),
)),
);
mergeMap(req => shouldParseMultipart(req)
? parseMultipart(opts)(req)
: throwError(
new HttpError(`Content-Type must be of type ${ContentType.MULTIPART_FORM_DATA}`, HttpStatus.PRECONDITION_FAILED)
)),
map(req => req as T & WithFile),