59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
// Hand-written mirror of arr-api's /api/health schema. `just gen-client`
|
|
// output (src/api/) is uncommitted, so CI's tsc cannot see it — this one
|
|
// endpoint stays hand-typed until the generated client is wired in.
|
|
|
|
export type CheckStatus = "ok" | "unreachable" | "unconfigured";
|
|
|
|
export interface Check {
|
|
status: CheckStatus;
|
|
detail?: string;
|
|
}
|
|
|
|
/** One enabled subtitle provider (#200). */
|
|
export interface ProviderCheck {
|
|
id: string;
|
|
status: CheckStatus;
|
|
detail?: string;
|
|
}
|
|
|
|
/** The subtitle lane: providers in use, the selected engine, the binaries. */
|
|
export interface SubtitleHealth {
|
|
providers: ProviderCheck[];
|
|
translation?: Check | null;
|
|
alass: Check;
|
|
ffmpeg: Check;
|
|
}
|
|
|
|
export interface HealthReport {
|
|
status: "ok" | "degraded";
|
|
version: string;
|
|
prowlarr: Check;
|
|
transmission: Check;
|
|
tmdb: Check;
|
|
subtitles: SubtitleHealth;
|
|
}
|
|
|
|
export type Probe =
|
|
| { kind: "report"; report: HealthReport; roundtripMs: number }
|
|
| { kind: "unreachable"; detail: string };
|
|
|
|
/** One probe of the daemon. The endpoint always answers 200 with a verdict in
|
|
* the body; anything else means the daemon itself is the outage. */
|
|
export async function probeHealth(): Promise<Probe> {
|
|
const started = performance.now();
|
|
try {
|
|
const response = await fetch("/api/health");
|
|
if (!response.ok) {
|
|
return { kind: "unreachable", detail: `http ${response.status}` };
|
|
}
|
|
const report = (await response.json()) as HealthReport;
|
|
return {
|
|
kind: "report",
|
|
report,
|
|
roundtripMs: Math.round(performance.now() - started),
|
|
};
|
|
} catch {
|
|
return { kind: "unreachable", detail: "no response" };
|
|
}
|
|
}
|