Poll for the placement suggestion instead of waiting on it

Matching pictures to the script is a model call and cannot answer inside the
few seconds the API gateway allows, so it returned "Function timed out". It now
starts in the background and this waits for it, the same way frames and joins
already do.
This commit is contained in:
gator 2026-09-07 21:25:52 +00:00
parent 838f308ba9
commit d175b3b926

View file

@ -366,6 +366,21 @@ function bindPics() {
if (!PICS.length) { showMsg("msg", "Add a picture first."); return; }
sg.disabled = true; sg.textContent = "Reading the script…";
var r = await api("suggest_image_placements", { email: email, project_id: pid });
if (!r.ok) { sg.disabled = false; sg.textContent = "Suggest where they fit"; showMsg("msg", r.error || "Could not suggest."); return; }
// Reading the script is a model call, far too slow to answer inside one
// request, so it runs in the background and we wait for it here.
if (r.pending) {
document.getElementById("sugnote").textContent = r.status_text || "Reading the script…";
var waited = 0;
r = await new Promise(function (done) {
var t = setInterval(async function () {
waited += 4;
var g = await api("suggest_image_placements", { email: email, project_id: pid });
if (g.ok && !g.pending) { clearInterval(t); done(g); return; }
if (waited > 150) { clearInterval(t); done({ ok: false, error: "That is taking unusually long." }); }
}, 4000);
});
}
sg.disabled = false; sg.textContent = "Suggest where they fit";
document.getElementById("sugnote").textContent = r.status_text || "";
if (!r.ok) { showMsg("msg", r.error || "Could not suggest."); return; }