fix(api): проверять достоверность WAN и не опрашивать выключенные серверы
This commit is contained in:
1 parent
4f084222ad
commit
d91cc77cda
13 files changed
+353
-12
No files matched your search
@@ -24,6 +24,7 @@ import {
|
||||
} from "../modules/servers/service/servers-service.js"
|
||||
import { getServerRowById } from "../modules/servers/repository/servers-repository.js"
|
||||
import {serverReadForUser} from "../modules/servers/mapper/servers-mapper.js"
|
||||
import { readInternetPathRows } from "../services/internet-path-snapshot.js"
|
||||
|
||||
// ── plugin ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -96,6 +97,7 @@ const serversRoutes: FastifyPluginAsyncZod = async (app) => {
|
||||
const params = req.params as ServerIdParams
|
||||
const server = await getServerReadById(params.id)
|
||||
if (!server) return reply.status(404).send({ error: "Server not found" })
|
||||
if (server.enabled === false) return reply.status(409).send({ error: "Сервер выключен. Опрос WAN не выполнялся" })
|
||||
|
||||
const toIp = (raw: string | null | undefined): string | null => {
|
||||
const v = String(raw ?? "").trim()
|
||||
@@ -144,15 +146,16 @@ const serversRoutes: FastifyPluginAsyncZod = async (app) => {
|
||||
try {
|
||||
const row = await getServerRowById(params.id)
|
||||
if (!row) return reply.status(404).send({ error: "Server not found" })
|
||||
if (row.enabled === false) return reply.status(409).send({ error: "Сервер выключен. Опрос WAN не выполнялся" })
|
||||
const client = MikrotikClient.fromServer(row)
|
||||
const isTrue = (v: unknown) => {
|
||||
const s = String(v ?? "").trim().toLowerCase()
|
||||
return s === "true" || s === "yes"
|
||||
}
|
||||
const [dhcpRaw, ipAddrs, routes] = await Promise.all([
|
||||
client.get<Array<Record<string, string>>>("/ip/dhcp-client").catch(() => []),
|
||||
client.getIpAddresses().catch(() => []),
|
||||
client.getIpRoutes().catch(() => []),
|
||||
client.get<unknown>("/ip/dhcp-client").then(raw => readInternetPathRows(raw, "WAN DHCP", ["interface"])),
|
||||
client.get<unknown>("/ip/address").then(raw => readInternetPathRows(raw, "WAN addresses", ["address", "interface"])),
|
||||
client.get<unknown>("/ip/route").then(raw => readInternetPathRows(raw, "WAN routes", ["dst-address"])),
|
||||
])
|
||||
|
||||
const defaultRoute = routes
|
||||
@@ -225,7 +228,7 @@ const serversRoutes: FastifyPluginAsyncZod = async (app) => {
|
||||
uplinks,
|
||||
})
|
||||
} catch (err) {
|
||||
return reply.status(502).send({ error: err instanceof Error ? err.message : "Failed to read WAN runtime" })
|
||||
return reply.status(502).send({ error: err instanceof Error ? `WAN: ${err.message}` : "Не удалось прочитать состояние WAN" })
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user