fix(jd): publish Guanghu router runtime source
This commit is contained in:
parent
e82a377b58
commit
e2bb573a58
14 changed files with 1492 additions and 73 deletions
|
|
@ -104,6 +104,42 @@ class WorkOrderManager {
|
|||
return { ok: true, order: publicOrder(order) };
|
||||
}
|
||||
|
||||
pendingForApprover(authorizerId, now = Date.now() / 1000) {
|
||||
const id = String(authorizerId || "");
|
||||
return [...this.workorders.values()]
|
||||
.filter(order => (
|
||||
order.state === "pending"
|
||||
&& order.authorizerId === id
|
||||
&& now <= order.expiresAt
|
||||
))
|
||||
.sort((left, right) => left.createdAt - right.createdAt)
|
||||
.map(publicOrder);
|
||||
}
|
||||
|
||||
inspectPending(workorderId, now = Date.now() / 1000) {
|
||||
const order = this.workorders.get(String(workorderId || ""));
|
||||
if (!order) return { ok: false, reason: "request_not_found" };
|
||||
if (now > order.expiresAt) return { ok: false, reason: "request_expired" };
|
||||
if (order.state !== "pending") return { ok: false, reason: "request_already_closed" };
|
||||
return { ok: true, order: publicOrder(order) };
|
||||
}
|
||||
|
||||
approveById(workorderId, authorizerId, now = Date.now() / 1000) {
|
||||
const order = this.workorders.get(String(workorderId || ""));
|
||||
if (!order) return { ok: false, reason: "request_not_found" };
|
||||
if (now > order.expiresAt) return { ok: false, reason: "request_expired" };
|
||||
if (order.state !== "pending") return { ok: false, reason: "request_already_closed" };
|
||||
if (!order.authorizerId || order.authorizerId !== String(authorizerId || "")) {
|
||||
return { ok: false, reason: "authorizer_mismatch" };
|
||||
}
|
||||
order.state = "approved";
|
||||
order.approvedAt = now;
|
||||
order.approvalHash = "";
|
||||
order.handoffHash = "";
|
||||
this.persist();
|
||||
return { ok: true, order: publicOrder(order) };
|
||||
}
|
||||
|
||||
claim(id, claimToken, now = Date.now() / 1000) {
|
||||
const order = this.workorders.get(id);
|
||||
if (!order || !safeEqual(order.claimHash, hash(claimToken || ""))) return { ok: false, reason: "claim_not_found" };
|
||||
|
|
|
|||
Loading…
Reference in a new issue