media-sucker/www/sucker.mjs

47 lines
1.3 KiB
JavaScript

const MILLISECOND = 1
const SECOND = 1000
async function update() {
let resp = await fetch("status.json", {cache: "no-store"})
let s = await resp.json()
for (let activity of ["reader", "encoder"]) {
let val = s.status[activity]
let e = document.querySelector(`.status .${activity}`)
e.textContent = val
if (val == "idle") {
e.classList.add("is-hidden")
} else {
e.classList.remove("is-hidden")
}
}
let qtmpl = document.querySelector("template.job-item").content
let qelem = document.querySelector(".jobs")
while (qelem.firstChild) qelem.firstChild.remove()
for (let qitem of s.queue) {
let e = qtmpl.cloneNode(true)
e.querySelector(".job-title").textContent = qitem.title
e.querySelector(".job-status").textContent = qitem.status
e.querySelector("progress").value = qitem.complete
qelem.append(e)
}
let fileItem = document.querySelector("template.panel-file-item").content
for (let section of ["video", "audio"]) {
let e = document.querySelector(`.${section} .items`)
while (e.firstChild) e.firstChild.remove()
for (let fn of s.finished[section]) {
let item = fileItem.cloneNode(true)
item.querySelector(".filename").textContent = fn
e.append(item)
}
}
}
setInterval(update, 2 * SECOND)
update()
// vi: ts=2 sw=2 et ai