From 61210c6640c92eb85032a54a96568e51334ab2b9 Mon Sep 17 00:00:00 2001 From: gator Date: Sun, 6 Sep 2026 15:29:00 +0000 Subject: [PATCH] Poll for the shot image, since drawing is now asynchronous --- script.html | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/script.html b/script.html index 66adca3..cdd9f65 100644 --- a/script.html +++ b/script.html @@ -184,9 +184,32 @@ function wire(locked) { photo_id: ph ? ph.value : undefined }); b.disabled = true; b.textContent = "Drawing…"; var r = await api("make_shot_image", { email: email, project_id: pid, index: idx }); - b.disabled = false; - if (!r.ok) { b.textContent = "Try again"; showMsg("msg", r.error || "Could not make that frame."); return; } - load(); + if (!r.ok) { + b.disabled = false; b.textContent = "Try again"; + showMsg("msg", r.error || "Could not make that frame."); + return; + } + // Drawing takes about half a minute and runs on the server, so the call + // above returns straight away. Watch the shot until the frame appears. + var waited = 0; + var tick = setInterval(async function () { + waited += 4; + var g = await api("get_project", { email: email, project_id: pid }); + var seg = (g.ok && g.script && g.script.segments || []).filter(function (x) { + return parseInt(x.index, 10) === idx; })[0]; + if (seg && seg.draw_error) { + clearInterval(tick); + b.disabled = false; b.textContent = "Try again"; + showMsg("msg", "That frame did not draw: " + seg.draw_error); + return; + } + if (seg && seg.plate_url) { clearInterval(tick); load(); return; } + if (waited > 120) { + clearInterval(tick); + b.disabled = false; b.textContent = "Try again"; + showMsg("msg", "That frame is taking unusually long. Try again in a moment."); + } + }, 4000); }); });