From f3ab34f22b53b32831e7e537b172145c7941d922 Mon Sep 17 00:00:00 2001 From: AlexisG Date: Thu, 24 Oct 2024 11:01:36 +0200 Subject: [PATCH] fix: Paper creation from the Cozy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “File” doesn't have exactly the same attributes between Chrome and Firefox! In this case, we were using the `lastModifiedDate` attribute, but it doesn't exist on Firefox. --- src/helpers/createPdfAndSave.js | 3 ++- src/helpers/createPdfAndSave.spec.js | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/createPdfAndSave.js b/src/helpers/createPdfAndSave.js index 9eb1cfb8..f2918750 100644 --- a/src/helpers/createPdfAndSave.js +++ b/src/helpers/createPdfAndSave.js @@ -101,8 +101,9 @@ export const createPdfAndSave = async ({ // Created first document of PDFDocument let pdfDoc = isAlreadyPDFDoc ? data[0].file : await PDFDocument.create() + // On Firefox, the lastModifiedDate doesn't exist, prefer the lastModified attribute const datetime = isAlreadyPDFDoc - ? pdfDoc.lastModifiedDate.toISOString() + ? new Date(pdfDoc.lastModified).toISOString() : pdfDoc.getCreationDate() // If present, we wish to keep the value in the metadata as a priority (e.g. foreign driver's license). diff --git a/src/helpers/createPdfAndSave.spec.js b/src/helpers/createPdfAndSave.spec.js index 7c31e8dd..3069ed3e 100644 --- a/src/helpers/createPdfAndSave.spec.js +++ b/src/helpers/createPdfAndSave.spec.js @@ -65,7 +65,6 @@ describe('createAndSavePdf', () => { const filePDF = new File(['bob'], 'bob.pdf', { type: 'application/pdf' }) - filePDF.lastModifiedDate = new Date() const fileJPG = new File(['bob'], 'bob.jpg', { type: 'image/jpg' })