don't get ourselves banned by repeatedly polling an expired download

main
xenofem 2022-05-25 08:56:55 -04:00
parent 4276189595
commit 6ef96a9dc5
1 changed files with 10 additions and 2 deletions

View File

@ -6,7 +6,14 @@ document.addEventListener("DOMContentLoaded", () => {
updateInterval = setInterval(() => {
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) => {
for (const [index, offset] of info.offsets.entries()) {
table.children[index].className = (offset > info.available) ? "unavailable" : "";
@ -14,6 +21,7 @@ document.addEventListener("DOMContentLoaded", () => {
if (info.available === info.file.size) {
clearInterval(updateInterval);
}
});
})
.catch(console.error);
}, 5000);
});