21 lines
931 B
TypeScript
21 lines
931 B
TypeScript
import type { FastifyPluginAsyncZod } from "@fastify/type-provider-zod"
|
|
import type { TrafficFlowHostStatus } from "@mmapp/contracts/traffic-flow"
|
|
|
|
export function createTrafficFlowHostRoutes(deps: {
|
|
status: () => Promise<TrafficFlowHostStatus>
|
|
reconcile: () => Promise<TrafficFlowHostStatus>
|
|
}): FastifyPluginAsyncZod {
|
|
return async app => {
|
|
app.get("/traffic/flow/host-status", async () => deps.status())
|
|
app.post("/traffic/flow/host-reconcile", async (_req, reply) => {
|
|
try {
|
|
const hostStatus = await deps.reconcile()
|
|
if (!hostStatus.configured) return reply.status(409).send({ error: "Автоматизация хоста NetFlow не настроена" })
|
|
return { ok: true, hostStatus }
|
|
} catch (error) {
|
|
return reply.status(502).send({ error: error instanceof Error ? error.message : "Настройки хоста не применены" })
|
|
}
|
|
})
|
|
}
|
|
}
|