From cd5fd13f1cfc0ef0d190fa2d658f3e2dba33496c Mon Sep 17 00:00:00 2001 From: Gabriel Poma Date: Tue, 15 Jul 2025 18:46:32 +0200 Subject: [PATCH] storeFileName with parameters file and filename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lors de la modification d'un pdf dans la page organisation, il faut prendre le pdf modifié et non le pdf dans l'input originel L'id de l'input était hardcodé dans la fonction --- public/js/common.js | 7 +++---- public/js/metadata.js | 5 +++-- public/js/organization.js | 1 + public/js/signature.js | 5 +++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/public/js/common.js b/public/js/common.js index 8620c88..0097f09 100644 --- a/public/js/common.js +++ b/public/js/common.js @@ -60,10 +60,9 @@ async function loadFileFromCache(cacheUrl, pageUrl) { document.getElementById('input_pdf_upload').dispatchEvent(new Event("change")); } -async function storeFileInCache() { - let cache = await caches.open('pdf'); - let filename = document.getElementById('input_pdf_upload').files[0].name; - let response = new Response(document.getElementById('input_pdf_upload').files[0], { "status" : 200, "statusText" : "OK" }); +async function storeFileInCache(file, filename, cacheStore = 'pdf') { + let cache = await caches.open(cacheStore); + let response = new Response(file, { "status" : 200, "statusText" : "OK" }); await cache.put('/pdf/'+filename, response); } diff --git a/public/js/metadata.js b/public/js/metadata.js index 2f1740b..b88ca2b 100644 --- a/public/js/metadata.js +++ b/public/js/metadata.js @@ -328,8 +328,9 @@ async function pageUpload() { }) document.getElementById('input_pdf_upload').addEventListener('change', async function(event) { if(await canUseCache()) { - storeFileInCache(); - history.pushState({}, '', '/metadata#'+document.getElementById('input_pdf_upload').files[0].name); + const file = document.getElementById('input_pdf_upload').files[0] + storeFileInCache(file, file.name); + history.pushState({}, '', '/metadata#'+file.name); } pageMetadata(null); }); diff --git a/public/js/organization.js b/public/js/organization.js index f0d452f..30fb46d 100644 --- a/public/js/organization.js +++ b/public/js/organization.js @@ -659,6 +659,7 @@ async function save(order) { const newPDF = new Blob([await pdf.save()], {type: "application/pdf"}); await download(newPDF, filename+".pdf"); + await storeFileInCache(newPDF, filename+'.pdf'); } function mm2points(mm) { diff --git a/public/js/signature.js b/public/js/signature.js index 2ec751b..10c024a 100644 --- a/public/js/signature.js +++ b/public/js/signature.js @@ -1148,8 +1148,9 @@ async function pageUpload() { document.getElementById('input_pdf_upload').focus(); document.getElementById('input_pdf_upload').addEventListener('change', async function(event) { if(await canUseCache()) { - storeFileInCache(); - history.pushState({}, '', '/signature#'+document.getElementById('input_pdf_upload').files[0].name); + const file = document.getElementById('input_pdf_upload').files[0] + storeFileInCache(file, file.name); + history.pushState({}, '', '/signature#'+file.name); } pageSignature(null); });