diff --git a/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/feasibility-aap/attachments/page.tsx b/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/feasibility-aap/attachments/page.tsx index 28784c18b..310f586eb 100644 --- a/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/feasibility-aap/attachments/page.tsx +++ b/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/feasibility-aap/attachments/page.tsx @@ -17,7 +17,7 @@ import { } from "./_components/attachments.hook"; const ACCEPTED_FILE_TYPES = ".pdf, .jpg, .jpeg, .png" as const; -const MAX_FILE_SIZE = "2Mo" as const; +const MAX_FILE_SIZE = "15Mo" as const; const hintMessage = `Formats supportés : ${ACCEPTED_FILE_TYPES} avec un poids maximum de ${MAX_FILE_SIZE}`; const schema = z diff --git a/packages/reva-api/modules/feasibility/dematerialized-feasibility-file/features/createOrUpdateAttachments.ts b/packages/reva-api/modules/feasibility/dematerialized-feasibility-file/features/createOrUpdateAttachments.ts index 7d28205d3..d76715b9d 100644 --- a/packages/reva-api/modules/feasibility/dematerialized-feasibility-file/features/createOrUpdateAttachments.ts +++ b/packages/reva-api/modules/feasibility/dematerialized-feasibility-file/features/createOrUpdateAttachments.ts @@ -15,6 +15,8 @@ import { getDematerializedFeasibilityFileWithAttachmentsByCandidacyId } from "./ import { resetDFFSentToCandidateState } from "./resetDFFSentToCandidateState"; import { allowFileTypeByDocumentType } from "../../../../modules/shared/file/allowFileTypes"; +const MAX_UPLOAD_SIZE = 15728640; // 15Mo + export const createOrUpdateAttachments = async ({ candidacyId, input: { @@ -68,19 +70,6 @@ export const createOrUpdateAttachments = async ({ existingFiles.push(...existingOtherAttachmentsFiles); } - if (existingFiles.length) { - await Promise.all( - existingFiles.map(({ file: { path } }) => deleteFile(path)), - ); - await prismaClient.dFFAttachment.deleteMany({ - where: { - id: { - in: existingFiles.map(({ id }) => id), - }, - }, - }); - } - const idCardFile = await getUploadedFile(idCard); const equivalenceOrExemptionProofFile = equivalenceOrExemptionProof @@ -139,6 +128,27 @@ export const createOrUpdateAttachments = async ({ } } + for (const { file } of fileAndIds) { + if (file._buf.length > MAX_UPLOAD_SIZE) { + throw new Error( + `Le fichier ${file.filename} est trop volumineux (${(file._buf.length / 1024 / 1024).toFixed(2)} Mo). La taille maximale autorisée est de ${MAX_UPLOAD_SIZE / 1024 / 1024} Mo.`, + ); + } + } + + if (existingFiles.length) { + await Promise.all( + existingFiles.map(({ file: { path } }) => deleteFile(path)), + ); + await prismaClient.dFFAttachment.deleteMany({ + where: { + id: { + in: existingFiles.map(({ id }) => id), + }, + }, + }); + } + for (const { file, filePath } of fileAndIds) { await uploadFileToS3({ filePath,