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 ce07f59
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 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);
}
}
2 changes: 1 addition & 1 deletion templates/compress.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<span id="is_mobile" class="d-md-none"></span>
<script src="<?php echo $REVERSE_PROXY_URL; ?>/vendor/bootstrap.bundle.min.js?5.1.3"></script>
<script>
var defaultFields = <?php echo json_encode(isset($METADATA_DEFAULT_FIELDS) ? $METADATA_DEFAULT_FIELDS : array()); ?>;
var maxSize = <?php echo $maxSize ?>;
</script>
<script src="<?php echo $REVERSE_PROXY_URL; ?>/js/compress.js?<?php echo ($COMMIT) ? $COMMIT : filemtime($ROOT."/public/js/compress.js") ?>"></script>
</body>
Expand Down

0 comments on commit ce07f59

Please sign in to comment.