feat(api): profil machine éditable, sonde, et réglages globaux apt-cacher-ng
- machines : updateMachine (PATCH /machines/:id) + POST /machines/:id/probe (sonde synchrone → faits + proposition de correction) ; MachineView expose machineKind/virtualization ; CreateMachineInput accepte aptProxyMode persistent - app_settings (clé/valeur, migration 0006) + service appSettings : défaut apt-cacher-ng (mode + url) ; applyProxyToAllMachines - routes /settings : GET, PUT /apt-proxy, POST /apt-proxy/apply-all Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { actionsRoutes } from "./actions.js";
|
||||
import { actionRequestsRoutes } from "./actionRequests.js";
|
||||
import { dockerRoutes } from "./docker.js";
|
||||
import { dbRoutes } from "./db.js";
|
||||
import { settingsRoutes } from "./settings.js";
|
||||
import { getServerCapabilities } from "../services/capabilities.js";
|
||||
import { getSystemMetrics, getSystemStatus } from "../services/system.js";
|
||||
|
||||
@@ -13,6 +14,7 @@ api.get("/capabilities", (c) => c.json(getServerCapabilities()));
|
||||
api.get("/system/status", (c) => c.json(getSystemStatus()));
|
||||
api.get("/system/metrics", (c) => c.json(getSystemMetrics()));
|
||||
api.route("/system/db", dbRoutes);
|
||||
api.route("/settings", settingsRoutes);
|
||||
api.route("/machines", machinesRoutes);
|
||||
api.route("/machines", actionsRoutes);
|
||||
api.route("/machines", dockerRoutes);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// server/routes/machines.ts
|
||||
import { Hono } from "hono";
|
||||
import {
|
||||
listMachines, createMachine, deleteMachine, getMachineRow, getCreds, testConnection,
|
||||
type CreateMachineInput,
|
||||
listMachines, createMachine, deleteMachine, updateMachine, getMachineRow, getCreds, testConnection,
|
||||
type CreateMachineInput, type UpdateMachineInput,
|
||||
} from "../services/machines.js";
|
||||
import { refreshMachine, getLatestSnapshot } from "../services/refresh.js";
|
||||
import { runProbe } from "../services/machineProbe.js";
|
||||
|
||||
export const machinesRoutes = new Hono();
|
||||
|
||||
@@ -43,6 +44,25 @@ machinesRoutes.post("/:id/refresh", async (c) => {
|
||||
}
|
||||
});
|
||||
|
||||
machinesRoutes.patch("/:id", async (c) => {
|
||||
const body = (await c.req.json()) as UpdateMachineInput;
|
||||
try {
|
||||
return c.json(updateMachine(c.req.param("id"), body));
|
||||
} catch (err) {
|
||||
return c.json({ error: (err as Error).message }, 400);
|
||||
}
|
||||
});
|
||||
|
||||
// Sonde synchrone (lecture seule) : renvoie faits + proposition de correction.
|
||||
machinesRoutes.post("/:id/probe", async (c) => {
|
||||
try {
|
||||
const o = await runProbe(c.req.param("id"));
|
||||
return c.json({ probe: o.probe, proposal: o.proposal, changes: o.changes });
|
||||
} catch (err) {
|
||||
return c.json({ error: (err as Error).message }, 400);
|
||||
}
|
||||
});
|
||||
|
||||
machinesRoutes.delete("/:id", (c) => {
|
||||
deleteMachine(c.req.param("id"));
|
||||
return c.json({ ok: true });
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// server/routes/settings.ts
|
||||
import { Hono } from "hono";
|
||||
import { getDefaultAptProxy, setDefaultAptProxy, type DefaultAptProxy } from "../services/appSettings.js";
|
||||
import { applyProxyToAllMachines } from "../services/machines.js";
|
||||
|
||||
export const settingsRoutes = new Hono();
|
||||
|
||||
// Réglages globaux exposés à l'UI.
|
||||
settingsRoutes.get("/", (c) => c.json({ defaultAptProxy: getDefaultAptProxy() }));
|
||||
|
||||
// Définit le proxy APT par défaut (apt-cacher-ng).
|
||||
settingsRoutes.put("/apt-proxy", async (c) => {
|
||||
const body = (await c.req.json()) as DefaultAptProxy;
|
||||
const mode = body.mode ?? "direct";
|
||||
const url = (body.url ?? "").trim() || null;
|
||||
return c.json(setDefaultAptProxy({ mode, url }));
|
||||
});
|
||||
|
||||
// Applique le proxy par défaut à toutes les machines existantes.
|
||||
settingsRoutes.post("/apt-proxy/apply-all", (c) => {
|
||||
const { mode, url } = getDefaultAptProxy();
|
||||
const updated = applyProxyToAllMachines(mode, url);
|
||||
return c.json({ ok: true, updated });
|
||||
});
|
||||
Reference in New Issue
Block a user