Files
Veyra/web/admin/src/lib/api.ts
T
Blizzard bffdb3858b
Checks / verify (push) Failing after 2m37s
feat: 基础框架搭建完毕
2026-10-07 09:27:47 +08:00

17 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export type ComponentStatus = "ready" | "unavailable" | "not_configured"
export type Health = {
status: "ready" | "not_ready"
checked_at: string
components: { postgresql: { status: ComponentStatus }; redis: { status: ComponentStatus } }
}
export async function getHealth(signal?: AbortSignal): Promise<Health> {
const response = await fetch("/api/v1/system/health", { signal, headers: { Accept: "application/json" } })
if (!response.ok && response.status !== 503) throw new Error(`服务请求失败(${response.status})`)
const data: unknown = await response.json()
if (!data || typeof data !== "object" || !("status" in data) || !("components" in data) || !("checked_at" in data)) throw new Error("服务返回了无效的状态数据")
const health = data as Health
const statuses = ["ready", "unavailable", "not_configured"]
if (!["ready", "not_ready"].includes(health.status) || typeof health.checked_at !== "string" || !statuses.includes(health.components?.postgresql?.status) || !statuses.includes(health.components?.redis?.status)) throw new Error("服务返回了无效的状态数据")
return health
}