fix(api): показывать источник и частичные сбои каталога интерфейсов

This commit is contained in:
Denozordec committed 2026-10-01 10:10:41 +07:00
1 parent ecd72d9750
commit c37498512f
9 files changed
+165 -44

No files matched your search

+21
View File
@@ -117,3 +117,24 @@ export type AppUserUpdate = z.infer<typeof appUserUpdateSchema>
export type UserBindingCreate = z.infer<typeof userBindingCreateSchema>
export type CatalogPeer = z.infer<typeof catalogPeerSchema>
export type CatalogInterface = z.infer<typeof catalogInterfaceSchema>
export const catalogInterfaceStateSchema = catalogInterfaceSchema.extend({
name: z.string().trim().min(1),
running: z.boolean().nullable(),
disabled: z.boolean().nullable(),
}).superRefine((iface, ctx) => {
if ((iface.type === "wg" || iface.type === "ipsec") && iface.peers === undefined && !iface.peersError) ctx.addIssue({ code: "custom", message: "Не подтверждён срез пиров." })
if (iface.peers && (iface.peers.some(peer => !peer.publicKey.trim()) || new Set(iface.peers.map(peer => peer.publicKey)).size !== iface.peers.length)) ctx.addIssue({ code: "custom", message: "Неоднозначные ключи пиров." })
})
export const interfaceCatalogStateSchema = z.object({
serverId: z.number().int().positive(),
source: z.enum(["snapshot", "traffic-history", "unknown"]),
sampledAt: z.string().refine(value => Number.isFinite(Date.parse(value)), "Некорректное время среза.").nullable(),
inventoryComplete: z.boolean(),
interfaces: z.array(catalogInterfaceStateSchema).refine(rows => new Set(rows.map(row => row.name)).size === rows.length, "Повторяющиеся интерфейсы."),
failures: z.array(z.object({ resource: z.enum(["interfaces", "wireguard", "ipsec"]), error: z.string().min(1) })),
}).superRefine((state, ctx) => {
if (state.inventoryComplete !== (state.source === "snapshot") || state.source === "unknown" && state.sampledAt !== null) ctx.addIssue({ code: "custom", message: "Противоречивые метаданные каталога." })
})
export type CatalogInterfaceState = z.infer<typeof catalogInterfaceStateSchema>
export type InterfaceCatalogState = z.infer<typeof interfaceCatalogStateSchema>