mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 01:34:31 +00:00
refactor(gateway): dedupe exec approvals node validation
This commit is contained in:
@@ -86,6 +86,15 @@ function toExecApprovalsPayload(snapshot: ExecApprovalsSnapshot) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveNodeIdOrRespond(nodeId: string, respond: RespondFn): string | null {
|
||||||
|
const id = nodeId.trim();
|
||||||
|
if (!id) {
|
||||||
|
respond(false, undefined, errorShape(ErrorCodes.INVALID_REQUEST, "nodeId required"));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
export const execApprovalsHandlers: GatewayRequestHandlers = {
|
export const execApprovalsHandlers: GatewayRequestHandlers = {
|
||||||
"exec.approvals.get": ({ params, respond }) => {
|
"exec.approvals.get": ({ params, respond }) => {
|
||||||
if (!assertValidParams(params, validateExecApprovalsGetParams, "exec.approvals.get", respond)) {
|
if (!assertValidParams(params, validateExecApprovalsGetParams, "exec.approvals.get", respond)) {
|
||||||
@@ -131,9 +140,8 @@ export const execApprovalsHandlers: GatewayRequestHandlers = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { nodeId } = params as { nodeId: string };
|
const { nodeId } = params as { nodeId: string };
|
||||||
const id = nodeId.trim();
|
const id = resolveNodeIdOrRespond(nodeId, respond);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
respond(false, undefined, errorShape(ErrorCodes.INVALID_REQUEST, "nodeId required"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await respondUnavailableOnThrow(respond, async () => {
|
await respondUnavailableOnThrow(respond, async () => {
|
||||||
@@ -165,9 +173,8 @@ export const execApprovalsHandlers: GatewayRequestHandlers = {
|
|||||||
file: ExecApprovalsFile;
|
file: ExecApprovalsFile;
|
||||||
baseHash?: string;
|
baseHash?: string;
|
||||||
};
|
};
|
||||||
const id = nodeId.trim();
|
const id = resolveNodeIdOrRespond(nodeId, respond);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
respond(false, undefined, errorShape(ErrorCodes.INVALID_REQUEST, "nodeId required"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await respondUnavailableOnThrow(respond, async () => {
|
await respondUnavailableOnThrow(respond, async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user