don't get ourselves banned by repeatedly polling an expired download
This commit is contained in:
parent
4276189595
commit
6ef96a9dc5
|
@ -6,7 +6,14 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
|
||||||
updateInterval = setInterval(() => {
|
updateInterval = setInterval(() => {
|
||||||
fetch(`info?code=${CODE}`)
|
fetch(`info?code=${CODE}`)
|
||||||
.then((res) => res.json())
|
.then((res) => {
|
||||||
|
if (res.status === 404) {
|
||||||
|
clearInterval(updateInterval);
|
||||||
|
return Promise.reject("Download not found");
|
||||||
|
} else {
|
||||||
|
return 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" : "";
|
||||||
|
@ -14,6 +21,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||||
if (info.available === info.file.size) {
|
if (info.available === info.file.size) {
|
||||||
clearInterval(updateInterval);
|
clearInterval(updateInterval);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(console.error);
|
||||||
}, 5000);
|
}, 5000);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue