Reset-Button, Service-Reorder, Port/HTTPS-Spalten, Healthcheck in Sidebar, Kategorien-Sync

This commit is contained in:
2026-07-19 15:14:44 +02:00
parent 20ea4d382d
commit fc1ea4fa70
16 changed files with 447 additions and 20 deletions

View File

@@ -0,0 +1,34 @@
import type { FastifyInstance } from "fastify";
import * as deviceRepo from "../db/repositories/devices.js";
import * as logRepo from "../db/repositories/logs.js";
/**
* Löscht ALLE Geräte und (per FK-Cascade) alle zugehörigen Dienste.
* Kategorien und Logs bleiben unangetastet.
*
* Erfordert { confirm: true } im Body zusätzlich zur Bestätigung im
* Frontend eine zweite Sicherung gegen versehentliche Aufrufe (z. B. per
* Skript oder Browser-Erweiterung).
*/
export async function resetRoutes(app: FastifyInstance): Promise<void> {
app.post("/api/reset", async (request, reply) => {
const body = request.body as { confirm?: boolean } | undefined;
if (body?.confirm !== true) {
return reply.code(400).send({
error: "Bestätigung erforderlich. Bitte { \"confirm\": true } im Body senden.",
});
}
const deviceCount = deviceRepo.listDevices().length;
const deletedCount = deviceRepo.deleteAllDevices();
logRepo.logScan({
type: "device",
level: "info",
message: `Reset: ${deletedCount} Gerät(e) und alle zugehörigen Dienste gelöscht`,
});
return { deletedDevices: deletedCount, previousDeviceCount: deviceCount };
});
}