Pausing Continious Upload
This commit is contained in:
parent
e849083401
commit
70ef013425
1 changed files with 33 additions and 3 deletions
|
|
@ -53,14 +53,35 @@ ctnbtn.classList = submitbtn.classList;
|
||||||
ctnbtn.value=gettext("Continious Upload");
|
ctnbtn.value=gettext("Continious Upload");
|
||||||
ctnbtn.type = "button";
|
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() {
|
async function uplaodfnc() {
|
||||||
|
|
||||||
|
ctnbtn.removeEventListener("click",uplaodfnc)
|
||||||
|
ctnbtn.addEventListener("click",pausing)
|
||||||
|
|
||||||
console.log(uploadInput.files);
|
console.log(uploadInput.files);
|
||||||
files = uploadInput.files;
|
files = uploadInput.files;
|
||||||
submitbtn.disabled = true;
|
submitbtn.disabled = true;
|
||||||
ctnbtn.disabled = true;
|
//ctnbtn.disabled = true;
|
||||||
actual = 0;
|
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;
|
csrfvalue = document.getElementsByName("csrfmiddlewaretoken")[0].value;
|
||||||
|
|
||||||
|
|
@ -92,6 +113,10 @@ async function uplaodfnc() {
|
||||||
|
|
||||||
// Upload files
|
// Upload files
|
||||||
for (let file of 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++;
|
actual++;
|
||||||
sendform = new FormData();
|
sendform = new FormData();
|
||||||
sendform.append("csrfmiddlewaretoken", csrfvalue);
|
sendform.append("csrfmiddlewaretoken", csrfvalue);
|
||||||
|
|
@ -111,7 +136,10 @@ async function uplaodfnc() {
|
||||||
if (!okpass) {
|
if (!okpass) {
|
||||||
window.alert("Error with " + file.name + "code" + await response.code);
|
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) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
@ -137,6 +165,8 @@ async function uplaodfnc() {
|
||||||
});
|
});
|
||||||
returned = await response.json();
|
returned = await response.json();
|
||||||
|
|
||||||
|
|
||||||
|
ctnbtn.disabled = true;
|
||||||
ctnbtn.value = gettext("Upload Complete Please reload the page");
|
ctnbtn.value = gettext("Upload Complete Please reload the page");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue