Skip to content

Commit

Permalink
compress: Max file size check in js was not working and there was unn…
Browse files Browse the repository at this point in the history
…ecessary code
  • Loading branch information
wincelau committed Dec 14, 2024
1 parent 79a7a90 commit 03ff52d
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions public/js/compress.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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);
}
}

0 comments on commit 03ff52d

Please sign in to comment.