From ce07f5903e5d563c261f926f4efa601c8987129d Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Sun, 15 Dec 2024 00:15:04 +0100 Subject: [PATCH] compress: Max file size check in js was not working and there was unnecessary code --- public/js/compress.js | 29 +++++++---------------------- templates/compress.html.php | 2 +- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/public/js/compress.js b/public/js/compress.js index b4cede6..c7b9b82 100644 --- a/public/js/compress.js +++ b/public/js/compress.js @@ -1,5 +1,12 @@ function handleFileChange() { const fileInput = document.getElementById('input_pdf_upload'); + + if(fileInput.files[0].size > maxSize) { + alert("Le PDF ne doit pas dépasser " + Math.round(maxSize/1024/1024) + " Mo"); + fileInput.value = null; + return; + } + const compressBtn = document.getElementById('compressBtn'); const dropdownCompressBtn = document.getElementById('dropdownMenuReference'); @@ -10,26 +17,4 @@ function handleFileChange() { compressBtn.disabled = true; dropdownCompressBtn.disabled = true; } - - document.getElementById('input_pdf_upload').addEventListener('change', async function(event) { - uploadAndLoadPDF(this); - }); } - -async function uploadAndLoadPDF(input_upload) { - const cache = await caches.open('pdf'); - for (let i = 0; i < input_upload.files.length; i++) { - if(input_upload.files[i].size > maxSize) { - - alert("Le PDF ne doit pas dépasser " + Math.round(maxSize/1024/1024) + " Mo"); - break; - } - let filename = input_upload.files[i].name; - let response = new Response(input_upload.files[i], { "status" : 200, "statusText" : "OK" }); - let urlPdf = '/pdf/'+filename; - await cache.put(urlPdf, response); - let pdfBlob = await getPDFBlobFromCache(urlPdf); - nbPDF++; - await loadPDF(pdfBlob, filename, nbPDF); - } -} \ No newline at end of file diff --git a/templates/compress.html.php b/templates/compress.html.php index afa0ea6..247bdc7 100644 --- a/templates/compress.html.php +++ b/templates/compress.html.php @@ -56,7 +56,7 @@