feat: add D601 dev backend path
This commit is contained in:
+26
-59
@@ -23,18 +23,9 @@ async function readJson(url: string, init?: RequestInit): Promise<unknown> {
|
||||
}
|
||||
|
||||
function coreInternalFetch(path: string, init?: { method?: string; body?: unknown }): unknown {
|
||||
const code = `
|
||||
const res = await fetch(${JSON.stringify(`http://backend-core:8080${path}`)}, ${JSON.stringify({
|
||||
method: init?.method ?? "GET",
|
||||
headers: init?.body === undefined ? undefined : { "content-type": "application/json" },
|
||||
body: init?.body === undefined ? undefined : JSON.stringify(init.body),
|
||||
})});
|
||||
const text = await res.text();
|
||||
let body = null;
|
||||
try { body = text ? JSON.parse(text) : null; } catch { body = { text }; }
|
||||
console.log(JSON.stringify({ ok: res.ok, status: res.status, body }));
|
||||
`;
|
||||
const result = runCommand(["docker", "exec", "unidesk-frontend", "bun", "-e", code], repoRoot);
|
||||
const command = ["docker", "exec", "unidesk-backend-core", "backend-core", "--fetch-json", `http://127.0.0.1:8080${path}`, "--method", init?.method ?? "GET"];
|
||||
if (init?.body !== undefined) command.push("--body-json", JSON.stringify(init.body));
|
||||
const result = runCommand(command, repoRoot);
|
||||
if (result.exitCode !== 0) {
|
||||
return { ok: false, exitCode: result.exitCode, stdoutTail: result.stdout.slice(-1200), stderrTail: result.stderr.slice(-1200) };
|
||||
}
|
||||
@@ -46,13 +37,14 @@ function coreInternalFetch(path: string, init?: { method?: string; body?: unknow
|
||||
}
|
||||
|
||||
function coreDockerStatusSummary(): unknown {
|
||||
const code = `
|
||||
const res = await fetch('http://backend-core:8080/api/nodes/docker-status');
|
||||
const text = await res.text();
|
||||
let body = null;
|
||||
try { body = text ? JSON.parse(text) : null; } catch { body = { text }; }
|
||||
const dockerStatuses = (body?.dockerStatuses || []).map((item) => {
|
||||
const status = item.dockerStatus || {};
|
||||
const result = runCommand(["docker", "exec", "unidesk-backend-core", "backend-core", "--fetch-json", "http://127.0.0.1:8080/api/nodes/docker-status"], repoRoot);
|
||||
if (result.exitCode !== 0) {
|
||||
return { ok: false, exitCode: result.exitCode, stdoutTail: result.stdout.slice(-1200), stderrTail: result.stderr.slice(-1200) };
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(result.stdout.trim()) as { ok?: boolean; status?: number; body?: { dockerStatuses?: Array<Record<string, unknown>> } };
|
||||
const dockerStatuses = (parsed.body?.dockerStatuses || []).map((item) => {
|
||||
const status = (item.dockerStatus || {}) as Record<string, unknown>;
|
||||
return {
|
||||
providerId: item.providerId,
|
||||
name: item.name,
|
||||
@@ -64,62 +56,37 @@ function coreDockerStatusSummary(): unknown {
|
||||
collectedAt: status.collectedAt,
|
||||
counts: status.counts,
|
||||
daemon: status.daemon,
|
||||
containersPreview: (status.containers || []).slice(0, 8).map((container) => ({
|
||||
id: container.id,
|
||||
name: container.name,
|
||||
image: container.image,
|
||||
state: container.state,
|
||||
status: container.status,
|
||||
ports: container.ports,
|
||||
})),
|
||||
containersPreview: Array.isArray(status.containers) ? status.containers.slice(0, 8) : [],
|
||||
},
|
||||
};
|
||||
});
|
||||
console.log(JSON.stringify({ ok: res.ok, status: res.status, body: { ok: body?.ok === true, dockerStatuses } }));
|
||||
`;
|
||||
const result = runCommand(["docker", "exec", "unidesk-frontend", "bun", "-e", code], repoRoot);
|
||||
if (result.exitCode !== 0) {
|
||||
return { ok: false, exitCode: result.exitCode, stdoutTail: result.stdout.slice(-1200), stderrTail: result.stderr.slice(-1200) };
|
||||
}
|
||||
try {
|
||||
return JSON.parse(result.stdout.trim()) as unknown;
|
||||
return { ok: parsed.ok, status: parsed.status, body: { ok: parsed.body !== undefined, dockerStatuses } };
|
||||
} catch {
|
||||
return { ok: true, stdoutTail: result.stdout.slice(-1200), stderrTail: result.stderr.slice(-1200) };
|
||||
}
|
||||
}
|
||||
|
||||
function coreSystemStatusSummary(): unknown {
|
||||
const code = `
|
||||
const res = await fetch('http://backend-core:8080/api/nodes/system-status?limit=24');
|
||||
const text = await res.text();
|
||||
let body = null;
|
||||
try { body = text ? JSON.parse(text) : null; } catch { body = { text }; }
|
||||
const systemStatuses = (body?.systemStatuses || []).map((item) => {
|
||||
const current = item.current || {};
|
||||
const result = runCommand(["docker", "exec", "unidesk-backend-core", "backend-core", "--fetch-json", "http://127.0.0.1:8080/api/nodes/system-status?limit=24"], repoRoot);
|
||||
if (result.exitCode !== 0) {
|
||||
return { ok: false, exitCode: result.exitCode, stdoutTail: result.stdout.slice(-1200), stderrTail: result.stderr.slice(-1200) };
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(result.stdout.trim()) as { ok?: boolean; status?: number; body?: { systemStatuses?: Array<Record<string, unknown>> } };
|
||||
const systemStatuses = (parsed.body?.systemStatuses || []).map((item) => {
|
||||
const current = (item.current || {}) as Record<string, unknown>;
|
||||
const history = Array.isArray(item.history) ? item.history : [];
|
||||
return {
|
||||
providerId: item.providerId,
|
||||
name: item.name,
|
||||
nodeStatus: item.nodeStatus,
|
||||
updatedAt: item.updatedAt,
|
||||
current: item.current ? {
|
||||
ok: current.ok,
|
||||
collectedAt: current.collectedAt,
|
||||
cpu: current.cpu,
|
||||
memory: current.memory,
|
||||
disk: current.disk,
|
||||
} : null,
|
||||
historyPreview: (item.history || []).slice(-8),
|
||||
historyCount: (item.history || []).length,
|
||||
current: item.current ? { ok: current.ok, collectedAt: current.collectedAt, cpu: current.cpu, memory: current.memory, disk: current.disk } : null,
|
||||
historyPreview: history.slice(-8),
|
||||
historyCount: history.length,
|
||||
};
|
||||
});
|
||||
console.log(JSON.stringify({ ok: res.ok, status: res.status, body: { ok: body?.ok === true, systemStatuses } }));
|
||||
`;
|
||||
const result = runCommand(["docker", "exec", "unidesk-frontend", "bun", "-e", code], repoRoot);
|
||||
if (result.exitCode !== 0) {
|
||||
return { ok: false, exitCode: result.exitCode, stdoutTail: result.stdout.slice(-1200), stderrTail: result.stderr.slice(-1200) };
|
||||
}
|
||||
try {
|
||||
return JSON.parse(result.stdout.trim()) as unknown;
|
||||
return { ok: parsed.ok, status: parsed.status, body: { ok: parsed.body !== undefined, systemStatuses } };
|
||||
} catch {
|
||||
return { ok: true, stdoutTail: result.stdout.slice(-1200), stderrTail: result.stderr.slice(-1200) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user