Merge branch 'fix/hub-operator-rows-close-stale' into unify/skills-20261114
This commit is contained in:
commit
6d1c28241b
6 files changed
+372
-13
No files matched your search
@@ -86,7 +86,7 @@
|
||||
|
||||
async function dismissJob(job) {
|
||||
const result = await sendJson("/api/inbox/dismiss", {id: job.id});
|
||||
if (!result.ok) {
|
||||
if (!result.ok && !closeGone(result, state.inbox.filter((item) => item.job && item.job.id === job.id).map(keyOf), "Close")) {
|
||||
toast("Cannot close", fail(result), false);
|
||||
}
|
||||
await load();
|
||||
|
||||
@@ -1,16 +1,53 @@
|
||||
const GONE_NOTICE = "already done or removed elsewhere";
|
||||
|
||||
function closeGone(result, keys, label) {
|
||||
if (result.status !== 404 || !keys.length) {
|
||||
return false;
|
||||
}
|
||||
state.inbox = state.inbox.filter((item) => !keys.includes(keyOf(item)));
|
||||
toast(`${label}: ${GONE_NOTICE}`, [], true);
|
||||
render(false);
|
||||
drawStream();
|
||||
return true;
|
||||
}
|
||||
|
||||
async function reloadGone(missing, keys, label) {
|
||||
await load();
|
||||
if (missing === null) {
|
||||
return;
|
||||
}
|
||||
const left = new Set(state.inbox.map(keyOf));
|
||||
if (keys.some((key) => !left.has(key))) {
|
||||
toast(`${label}: ${GONE_NOTICE}`, [], true);
|
||||
} else {
|
||||
toast(`${label}: not possible`, fail(missing), false);
|
||||
}
|
||||
}
|
||||
|
||||
async function submit(entries, label) {
|
||||
ui.busy = true;
|
||||
const signed = await proofFor(entries, label);
|
||||
const keys = entries.map(keyOf);
|
||||
let missing = null;
|
||||
const gone = (result) => {
|
||||
if (keys.length > 1 && result.status === 404) {
|
||||
missing = result;
|
||||
return true;
|
||||
}
|
||||
return closeGone(result, keys, label);
|
||||
};
|
||||
const signed = await proofFor(entries, label, gone);
|
||||
if (signed === null) {
|
||||
ui.busy = false;
|
||||
await load();
|
||||
await reloadGone(missing, keys, label);
|
||||
return false;
|
||||
}
|
||||
const result = await sendJson("/api/inbox/approve", {items: entries, proof: signed.proof});
|
||||
ui.busy = false;
|
||||
if (!result.ok || !result.data) {
|
||||
toast(`${label}: not possible`, fail(result), false);
|
||||
await load();
|
||||
if (!gone(result)) {
|
||||
toast(`${label}: not possible`, fail(result), false);
|
||||
}
|
||||
await reloadGone(missing, keys, label);
|
||||
return false;
|
||||
}
|
||||
known.batches.add(result.data.id);
|
||||
|
||||
@@ -38,10 +38,12 @@
|
||||
|
||||
let signing = false;
|
||||
|
||||
async function prove(path, fields, label) {
|
||||
async function prove(path, fields, label, handled) {
|
||||
const result = await sendJson(path, fields);
|
||||
if (!result.ok || !result.data) {
|
||||
toast(`${label}: not possible`, fail(result), false);
|
||||
if (!handled || !handled(result)) {
|
||||
toast(`${label}: not possible`, fail(result), false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (result.data.payload === null) {
|
||||
@@ -51,21 +53,21 @@
|
||||
return signed ? {proof: {payload: result.data.payload, assertion: signed}} : null;
|
||||
}
|
||||
|
||||
async function signedProof(path, fields, label) {
|
||||
async function signedProof(path, fields, label, handled) {
|
||||
if (signing) {
|
||||
toast(`${label}: not signed`, ["Another passkey signature is still open: finish or cancel it first; nothing was sent."], false);
|
||||
return null;
|
||||
}
|
||||
signing = true;
|
||||
try {
|
||||
return await prove(path, fields, label);
|
||||
return await prove(path, fields, label, handled);
|
||||
} finally {
|
||||
signing = false;
|
||||
}
|
||||
}
|
||||
|
||||
function proofFor(entries, label) {
|
||||
return signedProof("/api/sign", {items: entries}, label);
|
||||
function proofFor(entries, label, handled) {
|
||||
return signedProof("/api/sign", {items: entries}, label, handled);
|
||||
}
|
||||
|
||||
async function registerPasskey(output) {
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
ui.busy = true;
|
||||
const prepared = await sendJson(`/api/rule-requests/${encodeURIComponent(item.id)}/sign`, {});
|
||||
const signed = prepared.ok && prepared.data ? await assertion(prepared.data, label) : null;
|
||||
if (!prepared.ok || !prepared.data) {
|
||||
if ((!prepared.ok || !prepared.data) && !closeGone(prepared, [keyOf(item)], label)) {
|
||||
toast(`${label}: not possible`, fail(prepared), false);
|
||||
}
|
||||
const result = signed ? await sendJson(`/api/rule-requests/${encodeURIComponent(item.id)}/accept`, {rule: prepared.data.payload, assertion: signed}) : null;
|
||||
ui.busy = false;
|
||||
if (result) {
|
||||
if (result && !closeGone(result, [keyOf(item)], label)) {
|
||||
toast(result.ok ? `Created: ${short(item.title)}` : `${label}: not created`, result.ok ? [] : fail(result), result.ok);
|
||||
}
|
||||
await load();
|
||||
|
||||
Reference in new issue
Block a user