Skip to content

Commit

Permalink
Merge pull request #1074 from MTES-MCT/issue/2304
Browse files Browse the repository at this point in the history
[patch] (2304) Correction: Import dynamique de file-type
  • Loading branch information
superfeedboy authored Jan 3, 2025
2 parents 06501e6 + ad806f7 commit 8fdefff
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/api/server/middlewares/fileValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* eslint-disable no-param-reassign */
import { NextFunction, Request, Response } from 'express';
import { body } from 'express-validator';
import fileType from 'file-type';
import extensions from '#common/utils/allowed_file_extensions';
import { MAX_FILE_SIZE } from '#common/utils/max_file_size';

Expand All @@ -15,9 +14,10 @@ export default async (req: Request, res: Response, next: NextFunction) => {

const fn = body('attachments')
.custom(async () => {
const { fileTypeFromBuffer } = await import('file-type');
// si un des fichiers a un type interdit : générer une erreur
const types = await Promise.all(
files.map(f => fileType.fromBuffer(f.buffer)),
files.map(f => fileTypeFromBuffer(f.buffer)),
);

const wrongTypeFiles = types
Expand Down

0 comments on commit 8fdefff

Please sign in to comment.