stop checking for updated info when upload is complete

This commit is contained in:
xenofem 2022-05-24 22:47:58 -04:00
parent d5a48ee8bc
commit b2ee4ff7a8

View file

@ -1,14 +1,19 @@
let updateInterval;
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
const table = document.getElementById("download_contents").getElementsByTagName("tbody")[0]; const table = document.getElementById("download_contents").getElementsByTagName("tbody")[0];
if (table.children.length === 0) { return; } if (table.children.length === 0) { return; }
setInterval(() => { updateInterval = setInterval(() => {
fetch(`info?code=${CODE}`) fetch(`info?code=${CODE}`)
.then((res) => res.json()) .then((res) => res.json())
.then((info) => { .then((info) => {
for (const [index, offset] of info.offsets.entries()) { for (const [index, offset] of info.offsets.entries()) {
table.children[index].className = (offset > info.available) ? "unavailable" : ""; table.children[index].className = (offset > info.available) ? "unavailable" : "";
} }
if (info.available === info.file.size) {
clearInterval(updateInterval);
}
}); });
}, 5000); }, 5000);
}); });