Add progress bar to zipgrep

This commit is contained in:
rubenwardy
2025-04-27 17:35:09 +01:00
parent 4011cc56b6
commit 2e5ced23a8
3 changed files with 42 additions and 5 deletions

View File

@@ -44,10 +44,29 @@ async function pollTask(poll_url, disableTimeout) {
if (res && res.status) {
let status = res.status.toLowerCase();
if (status === "pending") {
status = "pending or unknown";
const progress = document.getElementById("progress");
if (status === "progress") {
progress.classList.remove("d-none");
const bar = progress.children[0];
const {current, total, running} = res.result;
const perc = Math.min( Math.max(100 * current / total, 0), 100);
bar.style.width = `${perc}%`;
bar.setAttribute("aria-valuenow", current);
bar.setAttribute("aria-valuemax", total);
const packages = running.map(x => `${x.author}/${x.name}`).join(", ");
document.getElementById("status").textContent = `Status: in progress (${current} / ${total})\n\n${packages}`;
} else {
progress.classList.add("d-none");
if (status === "pending") {
status = "pending or unknown";
}
document.getElementById("status").textContent = `Status: ${status}`;
}
document.getElementById("status").textContent = `Status: ${status}`;
}
if (res && res.status === "SUCCESS") {