const ws = new WebSocket(Deno.args[0]) const file = await Deno.readTextFile(Deno.args[1]) const outdir = Deno.args.length >= 3 ? Deno.args[2] : "." const note_filter = Deno.args.length >= 4 ? Deno.args[3] : "" const requeue = Deno.env.has("REQUEUE") function run_enqueue() { let kind = "http" for (const line of file.split("\n")) { if (!line.trim().length) continue else if (line.startsWith("[") && line.endsWith("]")) kind = line.substring(1, line.length - 1) else { const [name, rest] = line.split("=", 2) const [id, note] = rest.split(";", 2) if (note_filter.length && note != note_filter) continue const key = `${kind}:${id}`; ws.send(JSON.stringify({ t: "metadata", key, data: { output: outdir + "/" + name, title: name } })) ws.send(JSON.stringify({ t: "enqueue", key, ignore_complete: requeue })) } } ws.send(JSON.stringify({ t: "save" })) console.log("done"); } ws.onerror = () => console.error("ws error") ws.onclose = () => console.error("ws closed") ws.onopen = () => { console.log("ws open"); ws.send(JSON.stringify({ t: "register", name: "enqueuer", task_kinds: [] })) run_enqueue() } ws.onmessage = ev => { if (typeof ev.data != "string") return const p = JSON.parse(ev.data) if (p.t == "error") console.error(`error: ${p.message}`); }