From 70ef013425705770023802119e2b209af82d8659 Mon Sep 17 00:00:00 2001 From: loulous27 Date: Sun, 7 Dec 2025 19:50:48 +0100 Subject: [PATCH] Pausing Continious Upload --- photologue/static/upload.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/photologue/static/upload.js b/photologue/static/upload.js index ec09603..74bcd2e 100644 --- a/photologue/static/upload.js +++ b/photologue/static/upload.js @@ -53,14 +53,35 @@ ctnbtn.classList = submitbtn.classList; ctnbtn.value=gettext("Continious Upload"); ctnbtn.type = "button"; +var pause = false ; + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + + +async function pausing() { + pause = ! pause ; + if (pause) { + ctnbtn.value = gettext("Pausing upload"); + } else { + ctnbtn.value = gettext("Resume"); + } + + +} + async function uplaodfnc() { + ctnbtn.removeEventListener("click",uplaodfnc) + ctnbtn.addEventListener("click",pausing) + console.log(uploadInput.files); files = uploadInput.files; submitbtn.disabled = true; - ctnbtn.disabled = true; + //ctnbtn.disabled = true; actual = 0; - ctnbtn.value = gettext("Please be patient")+" 0% (" + actual + "/" + files.length + ")"; + ctnbtn.value = gettext("Pause the upload, be patient")+" 0% (" + actual + "/" + files.length + ")"; csrfvalue = document.getElementsByName("csrfmiddlewaretoken")[0].value; @@ -92,6 +113,10 @@ async function uplaodfnc() { // Upload files for (let file of files) { + while (pause){ + await sleep(100); + ctnbtn.value = gettext("Upload Paused") + " " + Math.round(100 * actual / total) + "% (" + actual + "/" + files.length + ")"; + } actual++; sendform = new FormData(); sendform.append("csrfmiddlewaretoken", csrfvalue); @@ -111,7 +136,10 @@ async function uplaodfnc() { if (!okpass) { window.alert("Error with " + file.name + "code" + await response.code); } - ctnbtn.value = gettext("Please be patient")+" " + Math.round(100 * actual / total) + "% (" + actual + "/" + files.length + ")"; + if (!pause) { + ctnbtn.value = gettext("Pause the upload, be patient")+" " + Math.round(100 * actual / total) + "% (" + actual + "/" + files.length + ")"; + } + } catch (e) { console.error(e); @@ -137,6 +165,8 @@ async function uplaodfnc() { }); returned = await response.json(); + + ctnbtn.disabled = true; ctnbtn.value = gettext("Upload Complete Please reload the page"); }