c3584f4ec8
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
// server/routes/actions.ts
|
|
import { Hono } from "hono";
|
|
import { readFileSync } from "node:fs";
|
|
import { runAction, listExecutions, getExecution } from "../services/execute.js";
|
|
import type { ActionType } from "@shared/types.js";
|
|
|
|
export const actionsRoutes = new Hono();
|
|
|
|
actionsRoutes.post("/:id/actions", async (c) => {
|
|
const { action } = (await c.req.json()) as { action: ActionType };
|
|
if (action !== "apt_full_upgrade" && action !== "reboot") {
|
|
return c.json({ error: "Action non autorisée" }, 400);
|
|
}
|
|
// Exécution lancée en arrière-plan; le suivi se fait via WebSocket.
|
|
runAction(c.req.param("id"), action).catch((err) =>
|
|
console.error("[action]", (err as Error).message),
|
|
);
|
|
return c.json({ ok: true, action }, 202);
|
|
});
|
|
|
|
actionsRoutes.get("/:id/executions", (c) => c.json(listExecutions(c.req.param("id"))));
|
|
|
|
actionsRoutes.get("/:id/executions/:execId", (c) => {
|
|
const e = getExecution(c.req.param("execId"));
|
|
return e ? c.json(e) : c.json({ error: "Exécution introuvable" }, 404);
|
|
});
|
|
|
|
actionsRoutes.get("/:id/executions/:execId/report", (c) => {
|
|
const e = getExecution(c.req.param("execId"));
|
|
if (!e?.reportPath) return c.json({ error: "Rapport introuvable" }, 404);
|
|
return c.text(readFileSync(e.reportPath, "utf8"));
|
|
});
|