fix(admin): complete web uploads, hold Esc during a run, keep focus and restores across job refreshes
The upload dialog's completion helper called `api`, which only exists inside
openUpload, so every web upload failed with a ReferenceError at its last step.
complete() now takes the dialog's api. A new test lexes every admin module and
fails when a top-level function uses api without taking it; it flags the old
upload.js.
During a run Esc is now stopped on the document in the capture phase. The old
listener sat on the dialog, so with the focus on the body (Start disables
itself, a click on the dialog's text) a second Esc closed the dialog and threw
the uploads away. The listener is added when a run starts and removed when it
ends or the dialog closes.
A sequence page refreshes after any ended job, because jobState names no
sequence. That refresh now redraws the header only when the sequence changed,
and the renders only when their list did. Stars, tags and renders are redrawn
through redraw(), so the keyboard focus stays put. restoreFocus finds an
unnamed control by its place, not as the first unnamed one. Failed thumbnails
are retried with a doubling wait and at most 8 tries, counted again once the
sequence changes.
The trash page reads the emptying it follows from /api/v1/jobs/{id} on every
load and after the event socket reconnects (api.events now emits
"reconnected"), so Empty no longer stays disabled when the job's end was lost.
A Restore in flight stays disabled across redraws.
The Library list counts cancelled jobs as ended (shared JOB_ENDED). Comments
are corrected in shared.js and library.js.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 641b9cd96b95d523990d1414c2bdead4138c5f4d)
This commit is contained in:
1 parent
4518ffe655
commit
81cf58227d
9 files changed
+379
-52
No files matched your search
@@ -88,16 +88,29 @@ export const api = {
|
||||
currentUser = null;
|
||||
},
|
||||
|
||||
/** Server events over WebSocket (cookie session), reconnecting with back-off until stop() is called. */
|
||||
/**
|
||||
* Server events over WebSocket (cookie session), reconnecting with back-off until stop() is called. The events sent
|
||||
* while it was not connected are lost, so once it is connected again onEvent gets { type: "reconnected" } (the
|
||||
* panel's own, never the server's): a page then reads again what it follows.
|
||||
*/
|
||||
events(onEvent) {
|
||||
let socket = null;
|
||||
let stopped = false;
|
||||
let opened = false;
|
||||
let delay = 1000;
|
||||
const connect = () => {
|
||||
if (stopped) return;
|
||||
socket = new WebSocket(`${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/api/v1/events`);
|
||||
socket.onopen = () => {
|
||||
delay = 1000;
|
||||
if (opened) {
|
||||
try {
|
||||
onEvent({ type: "reconnected" });
|
||||
} catch {
|
||||
// A listener that throws does not stop the events.
|
||||
}
|
||||
}
|
||||
opened = true;
|
||||
};
|
||||
socket.onmessage = (m) => {
|
||||
try {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { t, plural, applyStrings } from "../i18n.js";
|
||||
import { escapeHtml, attr, formatBytes, formatNumber, toast, errorText, confirmDialog, formDialog, markInvalid, emptyState, routeParams, redraw } from "../ui.js";
|
||||
import { icons } from "../icons.js";
|
||||
import { BULK_LIMIT, factsLine, captureText, cameraLabel, statusChips, lazyImage, watchImages, Selection, selectableGrid, chunks, saveFile, sequencesCsv, today, tagList, coverUrl, listed } from "./library/shared.js";
|
||||
import { BULK_LIMIT, factsLine, captureText, cameraLabel, statusChips, lazyImage, watchImages, Selection, selectableGrid, chunks, saveFile, sequencesCsv, today, tagList, coverUrl, listed, JOB_ENDED } from "./library/shared.js";
|
||||
import { renderSequence } from "./library/sequence.js";
|
||||
import { renderTrash } from "./library/trash.js";
|
||||
|
||||
@@ -138,8 +138,8 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
|
||||
location.hash = `#/library?id=${encodeURIComponent(key)}`;
|
||||
},
|
||||
onChange: () => {
|
||||
// "Select all" holds while sequences beyond the loaded rows stay selected; once none does (Esc, Ctrl+A, every card
|
||||
// unticked) the selection is the loaded rows' again: Select all comes back and a refresh drops sequences gone.
|
||||
// "Select all" holds while sequences beyond the loaded rows stay selected (unticking cards keeps those); once none
|
||||
// does (Esc, Ctrl+A) the selection is the loaded rows' again: Select all comes back and a refresh drops sequences gone.
|
||||
if (matching) {
|
||||
const loaded = new Set(rows.map((r) => r.id));
|
||||
if ([...selection.ids].every((id) => loaded.has(id))) matching = null;
|
||||
@@ -556,7 +556,7 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
|
||||
// Sequences that change (a job finished, an upload landed, someone deleted or retagged) show their new state.
|
||||
onEvent((e) => {
|
||||
if (e.type === "sequenceChanged") refreshSoon(800);
|
||||
else if (e.type === "jobState" && (e.state === "done" || e.state === "failed")) refreshSoon(1500);
|
||||
else if (e.type === "jobState" && JOB_ENDED.has(e.state)) refreshSoon(1500);
|
||||
});
|
||||
await load();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ export async function renderSequence(root, { api, setMeta, actions, onEvent }, i
|
||||
let frames = [];
|
||||
let cursor = null;
|
||||
let renders = [];
|
||||
/** The renders' list as last drawn (JSON), null before the first draw. */
|
||||
let rendersShown = null;
|
||||
let generation = 0;
|
||||
let timer = null;
|
||||
let jobTimer = null;
|
||||
@@ -135,15 +137,20 @@ export async function renderSequence(root, { api, setMeta, actions, onEvent }, i
|
||||
watchImages(cover);
|
||||
}
|
||||
|
||||
// Tags and stars are buttons: a redraw keeps the keyboard focus on the same one (a star by its id, a tag by its place).
|
||||
const tags = root.querySelector("#tags");
|
||||
tags.innerHTML = seq.tags.map((tag, i) => `<span class="tag" dir="auto">${escapeHtml(tag)}<button class="btn icon subtle tiny" type="button" data-remove="${i}"
|
||||
title="${attr(t("Admin.Sequence.RemoveTag.Tip", tag))}" aria-label="${attr(t("Admin.Sequence.RemoveTag.Tip", tag))}">${icons.close}</button></span>`).join("");
|
||||
redraw(tags, () => {
|
||||
tags.innerHTML = seq.tags.map((tag, i) => `<span class="tag" dir="auto">${escapeHtml(tag)}<button class="btn icon subtle tiny" type="button" data-remove="${i}"
|
||||
title="${attr(t("Admin.Sequence.RemoveTag.Tip", tag))}" aria-label="${attr(t("Admin.Sequence.RemoveTag.Tip", tag))}">${icons.close}</button></span>`).join("");
|
||||
});
|
||||
tags.querySelectorAll("[data-remove]").forEach((b) => b.addEventListener("click", () =>
|
||||
patch({ tags: seq.tags.filter((_, i) => i !== Number(b.dataset.remove)) }, "tag-add")));
|
||||
|
||||
const rating = root.querySelector("#rating");
|
||||
rating.innerHTML = [1, 2, 3, 4, 5].map((n) => `<button class="btn icon subtle star" type="button" id="star-${n}" data-star="${n}" aria-pressed="${n <= seq.rating}"
|
||||
aria-label="${attr(plural("Admin.Sequence.Stars", n))}" title="${attr(t(n === seq.rating ? "Admin.Sequence.Unrate.Tip" : "Admin.Sequence.Rate.Tip", n))}">${n <= seq.rating ? icons.starFilled : icons.star}</button>`).join("");
|
||||
redraw(rating, () => {
|
||||
rating.innerHTML = [1, 2, 3, 4, 5].map((n) => `<button class="btn icon subtle star" type="button" id="star-${n}" data-star="${n}" aria-pressed="${n <= seq.rating}"
|
||||
aria-label="${attr(plural("Admin.Sequence.Stars", n))}" title="${attr(t(n === seq.rating ? "Admin.Sequence.Unrate.Tip" : "Admin.Sequence.Rate.Tip", n))}">${n <= seq.rating ? icons.starFilled : icons.star}</button>`).join("");
|
||||
});
|
||||
rating.querySelectorAll("[data-star]").forEach((b) => b.addEventListener("click", () => {
|
||||
const n = Number(b.dataset.star);
|
||||
patch({ rating: n === seq.rating ? 0 : n }, `star-${n}`);
|
||||
@@ -399,13 +406,25 @@ export async function renderSequence(root, { api, setMeta, actions, onEvent }, i
|
||||
location.hash = back;
|
||||
}
|
||||
|
||||
/** The renders, drawn again only when their list changed (a refresh after every job must not move the focus). */
|
||||
async function loadRenders() {
|
||||
let list;
|
||||
try {
|
||||
renders = await api.get(`/api/v1/sequences/${encodeURIComponent(id)}/renders`);
|
||||
list = await api.get(`/api/v1/sequences/${encodeURIComponent(id)}/renders`);
|
||||
} catch {
|
||||
renders = [];
|
||||
// A failed refresh leaves the list shown; a first read that failed shows none.
|
||||
if (rendersShown !== null) return;
|
||||
list = [];
|
||||
}
|
||||
const key = JSON.stringify(list);
|
||||
if (key === rendersShown || !root.isConnected) return;
|
||||
rendersShown = key;
|
||||
renders = list;
|
||||
const host = root.querySelector("#renders");
|
||||
redraw(host, () => drawRenders(host));
|
||||
}
|
||||
|
||||
function drawRenders(host) {
|
||||
host.innerHTML = renders.length === 0 ? emptyState("Admin.Sequence.NoRenders") : `
|
||||
<div class="table renders" role="table" aria-labelledby="renders-title">
|
||||
<div class="thead" role="row"><span role="columnheader" data-i18n="Admin.Sequence.Render.Preset"></span>
|
||||
@@ -517,16 +536,21 @@ export async function renderSequence(root, { api, setMeta, actions, onEvent }, i
|
||||
].join("");
|
||||
}
|
||||
|
||||
/** Everything again after a change elsewhere; with frames, the photos too. */
|
||||
/**
|
||||
* Everything again after a change elsewhere; with frames, the photos too. Only what changed is drawn again (the header
|
||||
* when the sequence read differs from the one shown), so a refresh that finds nothing new leaves the page and the
|
||||
* keyboard focus as they were. True when the sequence changed.
|
||||
*/
|
||||
async function reload(withFrames) {
|
||||
const before = seq.framesVersion;
|
||||
const hero = seq.heroFrameId;
|
||||
const shown = seq;
|
||||
await reloadSequence();
|
||||
if (!root.isConnected || leaving) return;
|
||||
drawHeader();
|
||||
if (withFrames || seq.framesVersion !== before) await reloadFrames();
|
||||
else if (seq.heroFrameId !== hero) drawFrames();
|
||||
if (!root.isConnected || leaving) return false;
|
||||
const changed = JSON.stringify(seq) !== JSON.stringify(shown);
|
||||
if (changed) drawHeader();
|
||||
if (withFrames || seq.framesVersion !== shown.framesVersion) await reloadFrames();
|
||||
else if (seq.heroFrameId !== shown.heroFrameId) drawFrames();
|
||||
await loadRenders();
|
||||
return changed;
|
||||
}
|
||||
|
||||
function gone() {
|
||||
@@ -538,19 +562,21 @@ export async function renderSequence(root, { api, setMeta, actions, onEvent }, i
|
||||
|
||||
/**
|
||||
* After a job ended: thumbnail, proxy, verify and analysis jobs send no sequenceChanged, so the facts and status chips
|
||||
* are read again and the cover and photos that had no thumbnail yet are asked for again.
|
||||
* are read again and the cover and photos that had no thumbnail yet are asked for again, each less often and up to a
|
||||
* limit, from the start again once the sequence changed.
|
||||
*/
|
||||
async function afterJob() {
|
||||
jobTimer = null;
|
||||
if (!root.isConnected || leaving) return;
|
||||
await reload(false);
|
||||
if (root.isConnected && !leaving) retryImages(root);
|
||||
const changed = await reload(false);
|
||||
if (root.isConnected && !leaving) retryImages(root, changed);
|
||||
}
|
||||
|
||||
onEvent((e) => {
|
||||
if (e.type === "jobState") {
|
||||
// The event names no sequence: any job that ended may have worked on this one. The timer is not pushed back by the
|
||||
// next one, so a busy queue still refreshes the page every AFTER_JOB_MS.
|
||||
// The event names neither the job's kind nor its targets: any job that ended may have worked on this one. The timer
|
||||
// is not pushed back by the next one, so a busy queue still refreshes the page every AFTER_JOB_MS; a refresh that
|
||||
// finds the sequence and its renders as shown draws nothing.
|
||||
if (JOB_ENDED.has(e.state) && jobTimer === null) jobTimer = setTimeout(afterJob, AFTER_JOB_MS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// What the Library's views share (owner review 2, R6): sequence facts and status chips as the desktop cards show them,
|
||||
// a selection with Shift ranges, the keyboard of a grid of selectable items, chunked bulk calls and file downloads.
|
||||
// thumbnails and their retries after a job ended, the job states that end a job, delete lists cut to LISTED names, a
|
||||
// selection with Shift ranges, the keyboard of a grid of selectable items, chunked bulk calls and file downloads.
|
||||
import { t, plural, culture } from "../../i18n.js";
|
||||
import { escapeHtml, attr, formatNumber, formatDuration } from "../../ui.js";
|
||||
import { icons } from "../../icons.js";
|
||||
@@ -93,14 +94,26 @@ export function watchImages(root) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Retries of an image that had nothing to show, the first after RETRY_FIRST_MS and each next one after twice the wait, up to RETRY_LONGEST_MS. */
|
||||
const RETRY_TRIES = 8;
|
||||
const RETRY_FIRST_MS = 2000;
|
||||
const RETRY_LONGEST_MS = 60000;
|
||||
|
||||
/**
|
||||
* The images under root that had nothing to show (a thumbnail not built yet) asked for again, once a job that may have
|
||||
* built them ended: under an address the browser has not tried, so its first answer is not reused.
|
||||
* built them ended: under an address the browser has not tried, so its first answer is not reused. Each image waits
|
||||
* longer before every retry and stops after RETRY_TRIES, since some never get one (a photo whose original is missing);
|
||||
* fresh (the sequence itself changed, a pass may have built them) starts every image's count again.
|
||||
*/
|
||||
export function retryImages(root) {
|
||||
export function retryImages(root, fresh = false) {
|
||||
const now = Date.now();
|
||||
root.querySelectorAll("img.failed").forEach((img) => {
|
||||
const tries = fresh ? 0 : Number(img.dataset.tries ?? 0);
|
||||
if (tries >= RETRY_TRIES || (!fresh && now < Number(img.dataset.retryAt ?? 0))) return;
|
||||
img.dataset.tries = String(tries + 1);
|
||||
img.dataset.retryAt = String(now + Math.min(RETRY_FIRST_MS * 2 ** tries, RETRY_LONGEST_MS));
|
||||
const url = new URL(img.getAttribute("src"), location.href);
|
||||
url.searchParams.set("retry", String(Date.now()));
|
||||
url.searchParams.set("retry", String(now));
|
||||
img.classList.remove("failed");
|
||||
img.setAttribute("data-fallback", "");
|
||||
img.src = url.pathname + url.search;
|
||||
|
||||
@@ -20,6 +20,8 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
* the POST that queued it has answered, so the page looks the job up here once it has its id.
|
||||
*/
|
||||
const ended = new Map();
|
||||
/** Entries whose restore was sent and has not answered: their buttons stay disabled through every redraw. */
|
||||
const restoring = new Set();
|
||||
let timer = null;
|
||||
let jobTimer = null;
|
||||
|
||||
@@ -45,6 +47,7 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
const table = root.querySelector(".table");
|
||||
|
||||
async function load() {
|
||||
if (emptyJob !== null) await checkEmptyJob();
|
||||
try {
|
||||
const list = await api.get("/api/v1/archive/trash");
|
||||
entries = list.entries;
|
||||
@@ -75,7 +78,7 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
<span class="col-by ellipsis" role="cell" dir="auto">${escapeHtml(e.deletedBy ?? "—")}</span>
|
||||
<span class="muted nowrap" role="cell">${escapeHtml(formatDateTime(e.deletedAt))}</span>
|
||||
<span class="row-actions" role="cell"><button class="btn small" data-restore="${attr(e.name)}" data-i18n="Admin.Trash.Restore"
|
||||
data-i18n-title="${e.kind === "sequence" ? "Admin.Trash.RestoreSequence.Tip" : "Admin.Trash.RestorePhotos.Tip"}"></button></span>
|
||||
data-i18n-title="${e.kind === "sequence" ? "Admin.Trash.RestoreSequence.Tip" : "Admin.Trash.RestorePhotos.Tip"}" ${restoring.has(e.name) ? "disabled" : ""}></button></span>
|
||||
</div>`).join("")
|
||||
|| `<div class="row" role="row"><div class="wide" role="cell">${emptyState("Admin.Trash.IsEmpty",
|
||||
`<a class="btn small" href="${attr(back)}" data-i18n="Admin.Trash.Back" data-i18n-title="Admin.Trash.Back.Tip"></a>`)}</div></div>`;
|
||||
@@ -86,16 +89,19 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
}
|
||||
|
||||
async function restore(entry, button) {
|
||||
if (!entry) return;
|
||||
if (!entry || restoring.has(entry.name)) return;
|
||||
restoring.add(entry.name);
|
||||
button.disabled = true;
|
||||
let result;
|
||||
try {
|
||||
result = await api.post(`/api/v1/archive/trash/${encodeURIComponent(entry.name)}/restore`);
|
||||
} catch (err) {
|
||||
restoring.delete(entry.name);
|
||||
toast(errorText(err), true);
|
||||
if (button.isConnected) button.disabled = false;
|
||||
// The entry is gone (emptied or restored elsewhere): the list shows the trash as it is now.
|
||||
// The entry is gone (emptied or restored elsewhere): the list shows the trash as it is now; else its button, maybe
|
||||
// drawn again meanwhile, can be used again.
|
||||
if (err.status === 404) await load();
|
||||
else draw();
|
||||
return;
|
||||
}
|
||||
const lines = [result.kind === "sequence" ? t("Admin.Trash.RestoredSequence", entry.title)
|
||||
@@ -103,7 +109,9 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
// The server says, in the page's language, how many photos stayed in the trash and why (one sentence per reason).
|
||||
if (result.kept.length > 0 && result.message) lines.push(result.message);
|
||||
toast(lines.join(" "), result.kept.length > 0);
|
||||
// Until the list without the entry is drawn: a read that started before the restore answered still shows it.
|
||||
await load();
|
||||
restoring.delete(entry.name);
|
||||
}
|
||||
|
||||
/** Measure (dry run), name what goes, have "empty" typed, then queue the erase with the plan's fingerprint. */
|
||||
@@ -152,13 +160,29 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
}
|
||||
}
|
||||
|
||||
/** The emptying this page queued ended: its toast; the caller shows the trash again. */
|
||||
/** The emptying this page queued ended (its jobState event, or the job read): its toast; the caller shows the trash again. */
|
||||
function emptyEnded(e) {
|
||||
emptyJob = null;
|
||||
if (e.state === "done") toast(t("Admin.Trash.Emptied"));
|
||||
else toast(e.error || t("Admin.Trash.EmptyFailed"), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The emptying this page follows, read from the queue: its end may have come while the events were not connected,
|
||||
* and nothing sends it again. A job no longer listed is followed no more, so Empty never stays disabled.
|
||||
*/
|
||||
async function checkEmptyJob() {
|
||||
const id = emptyJob;
|
||||
let job;
|
||||
try {
|
||||
job = await api.get(`/api/v1/jobs/${encodeURIComponent(id)}`);
|
||||
} catch (err) {
|
||||
if (err.status === 404 && emptyJob === id) emptyJob = null;
|
||||
return;
|
||||
}
|
||||
if (emptyJob === id && JOB_ENDED.has(job.state)) emptyEnded(job);
|
||||
}
|
||||
|
||||
onEvent((e) => {
|
||||
if (e.type === "jobState" && JOB_ENDED.has(e.state)) {
|
||||
ended.set(e.jobId, e);
|
||||
@@ -180,6 +204,9 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
timer = setTimeout(() => {
|
||||
if (root.isConnected) load();
|
||||
}, 800);
|
||||
} else if (e.type === "reconnected") {
|
||||
// Events sent while the socket was down are lost: the trash, and the emptying it follows, are read again.
|
||||
if (root.isConnected) load();
|
||||
}
|
||||
});
|
||||
await load();
|
||||
|
||||
@@ -307,7 +307,8 @@ export function focusPlace(root) {
|
||||
|
||||
/**
|
||||
* Focuses the same control after a re-render, else the control at the same place in the same (or same-position) row,
|
||||
* else the first control left (an empty state's button).
|
||||
* else the first control left (an empty state's button). A control without a name (a tag's remove button) is found by
|
||||
* its place alone: matching its empty name would pick the first unnamed control instead.
|
||||
*/
|
||||
export function restoreFocus(root, place) {
|
||||
if (!place) return;
|
||||
@@ -320,7 +321,8 @@ export function restoreFocus(root, place) {
|
||||
else index = 0;
|
||||
}
|
||||
const controls = [...scope.querySelectorAll(FOCUSABLE)];
|
||||
(controls.find((c) => controlKey(c) === place.control) ?? controls[Math.min(Math.max(index, 0), controls.length - 1)])?.focus();
|
||||
const same = place.control ? controls.find((c) => controlKey(c) === place.control) : undefined;
|
||||
(same ?? controls[Math.min(Math.max(index, 0), controls.length - 1)])?.focus();
|
||||
}
|
||||
|
||||
/** Redraws with draw() and puts the keyboard focus back where it was. */
|
||||
|
||||
@@ -152,11 +152,12 @@ export function openUpload({ api, sequence, onDone } = {}) {
|
||||
});
|
||||
|
||||
// Esc closes only while nothing is being sent; Cancel stops a run. Chromium lets a dialog's cancel be prevented only
|
||||
// once per user activation, so during a run Esc is stopped at its keydown; the cancel handler stays for close requests
|
||||
// that do not come from the keyboard (a back gesture).
|
||||
dialog.addEventListener("keydown", (e) => {
|
||||
if (running && e.key === "Escape") e.preventDefault();
|
||||
});
|
||||
// once per user activation, so during a run Esc is stopped at its keydown, on the document in the capture phase: a
|
||||
// click on the dialog's text moves the focus to the body, and Esc from there would pass the dialog by. The cancel
|
||||
// handler stays for close requests that do not come from the keyboard (a back gesture).
|
||||
const stopEscape = (e) => {
|
||||
if (e.key === "Escape") e.preventDefault();
|
||||
};
|
||||
dialog.addEventListener("cancel", (e) => {
|
||||
if (running) e.preventDefault();
|
||||
});
|
||||
@@ -176,6 +177,7 @@ export function openUpload({ api, sequence, onDone } = {}) {
|
||||
clearTimeout(searchTimer);
|
||||
cancelAnimationFrame(frame);
|
||||
window.removeEventListener("beforeunload", guard);
|
||||
document.removeEventListener("keydown", stopEscape, true);
|
||||
window.removeEventListener("chronos:signed-out", signedOut);
|
||||
dialog.remove();
|
||||
resolve();
|
||||
@@ -456,6 +458,7 @@ export function openUpload({ api, sequence, onDone } = {}) {
|
||||
sameContent = new Map();
|
||||
const signal = controller.signal;
|
||||
window.addEventListener("beforeunload", guard);
|
||||
document.addEventListener("keydown", stopEscape, true);
|
||||
drawButtons();
|
||||
let changed = false;
|
||||
try {
|
||||
@@ -496,6 +499,7 @@ export function openUpload({ api, sequence, onDone } = {}) {
|
||||
running = false;
|
||||
controller = null;
|
||||
window.removeEventListener("beforeunload", guard);
|
||||
document.removeEventListener("keydown", stopEscape, true);
|
||||
todo.filter((i) => ACTIVE.has(i.state)).forEach((i) => setState(i, "cancelled"));
|
||||
drawButtons();
|
||||
drawTotal();
|
||||
@@ -629,7 +633,7 @@ export function openUpload({ api, sequence, onDone } = {}) {
|
||||
if (failure !== null && !filing(failure)) throw failure;
|
||||
setState(item, "verifying");
|
||||
try {
|
||||
await complete(item.uploadId, restore, signal);
|
||||
await complete(api, item.uploadId, restore, signal);
|
||||
} catch (err) {
|
||||
if (!(err instanceof ApiFailure && err.status === 409 && err.code === "photo_removed")) throw err;
|
||||
// Deleted from the sequence while it was on its way: not filed, and the server dropped the upload (R6).
|
||||
@@ -656,12 +660,12 @@ function filing(err) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes an upload (with restore, a photo deleted from the sequence meanwhile is filed anyway). A completion refused
|
||||
* while another one is filing the upload (the same photo started twice, a retry after a lost answer) waits for it: once
|
||||
* the upload is committed, completing again answers its frame. Only an upload that failed or was cancelled, or one that
|
||||
* stays busy for about a minute, fails the photo.
|
||||
* Completes an upload through api, the dialog's (with restore, a photo deleted from the sequence meanwhile is filed
|
||||
* anyway). A completion refused while another one is filing the upload (the same photo started twice, a retry after a
|
||||
* lost answer) waits for it: once the upload is committed, completing again answers its frame. Only an upload that
|
||||
* failed or was cancelled, or one that stays busy for about a minute, fails the photo.
|
||||
*/
|
||||
async function complete(uploadId, restore, signal) {
|
||||
async function complete(api, uploadId, restore, signal) {
|
||||
const url = `/api/v1/uploads/${uploadId}/complete${restore ? "?restore=true" : ""}`;
|
||||
for (let check = 0; ; check++) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user