Fix device approval

This commit is contained in:
Arjun Komath
2026-03-12 17:21:05 +11:00
parent d35997324d
commit 7f11acbd07
2 changed files with 10 additions and 5 deletions
-3
View File
@@ -278,9 +278,6 @@
this.devicesPending = [];
this.devicesPaired = [];
}
if (j.raw) {
this.log += '[devices] ' + j.raw.trim() + '\n';
}
} catch (e) {
this.log += '✗ Failed to load devices: ' + String(e) + '\n';
} finally {
+10 -2
View File
@@ -842,10 +842,18 @@ app.post("/setup/api/doctor", requireSetupAuth, async (_req, res) => {
app.get("/setup/api/devices", requireSetupAuth, async (_req, res) => {
const args = ["devices", "list", "--json", "--token", OPENCLAW_GATEWAY_TOKEN];
const result = await runCmd(OPENCLAW_NODE, clawArgs(args));
log.info("devices", `list exit=${result.code} output=${result.output}`);
try {
const data = JSON.parse(result.output);
const jsonMatch = result.output.match(/(\{[\s\S]*\}|\[[\s\S]*\])\s*$/);
if (!jsonMatch) {
log.warn("devices", "no JSON found in output");
return res.json({ ok: result.code === 0, raw: result.output });
}
const data = JSON.parse(jsonMatch[1]);
log.info("devices", `parsed keys=${Object.keys(data)} pending=${JSON.stringify(data.pending)} paired=${JSON.stringify(data.paired)}`);
return res.json({ ok: true, data, raw: result.output });
} catch {
} catch (parseErr) {
log.warn("devices", `JSON parse failed: ${parseErr.message}`);
return res.json({ ok: result.code === 0, raw: result.output });
}
});