feat: add direct car telemetry management

This commit is contained in:
2026-07-31 23:14:40 +02:00
parent 530162cbf7
commit e347a581e1
16 changed files with 447 additions and 57 deletions
+25
View File
@@ -82,6 +82,7 @@ const adbShortcutSchema = z.object({ name: z.string().trim().min(1).max(48), typ
}
return { name: value.name, ...target.data };
});
const clearTelemetrySchema = z.object({ mode: z.enum(["history", "all"]) });
type UserRow = { id: number; username: string; role: "admin"; password_hash: string };
type SessionUserRow = { id: number; username: string; role: "admin" };
@@ -505,6 +506,30 @@ export async function buildApp(config: AppConfig): Promise<FastifyInstance> {
return carTelemetry.store.overview();
});
app.post(
"/api/car/history/clear",
{ config: { rateLimit: { max: 4, timeWindow: "10 minutes" } } },
async (request, reply) => {
if (!requireUser(request, reply)) return;
const parsed = clearTelemetrySchema.safeParse(request.body);
if (!parsed.success) {
return reply.code(400).send({
error: { code: "INVALID_CLEAR_TELEMETRY_MODE", message: "Choose which car statistics to clear" }
});
}
const result = carTelemetry.store.clear(parsed.data.mode);
audit(database, {
actorUserId: request.authUser!.id,
action: "car.telemetry-clear",
result: "success",
ipAddress: clientAddress(request),
details: result
});
return result;
}
);
app.post(
"/api/network/configuration",
{ config: { rateLimit: { max: 3, timeWindow: "10 minutes" } } },