Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 10s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 10s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m12s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 3m4s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 8m17s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 10m36s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Version every /api route to /api/v1 (251 controller routes + ~24 Location
headers + the scanner callback URL + the Startup request-log literal),
uniform across the machine API, auth, scanner and scripted-build surfaces.
Add ApiVersionRewriteMiddleware: a legacy unversioned /api/* request is
rewritten (NOT redirected) to /api/v1/* in-pipeline — method, body, auth
headers and query survive — carrying RFC 8594 Deprecation/Sunset headers,
so curl / the future MCP server / bookmarks keep working. An already-
versioned path passes through; a future /api/v2 is never forced to v1.
Standardize the route convention (leading-slash absolute route per method,
no class-[Route] — except the two Scanner/Scripted controllers whose ~all
actions share a parametrized {id} prefix), enforced by ApiRouteVersioningTests
(^/api/v\d+/ over the whole Controllers.Api surface; browser-nav
/auth/oidc/login is out of scope).
Regenerate v1.json (160 paths, all /api/v1)/endpoint-index/v1.d.ts; sweep 945
SPA request literals + the test mocks (regex + positional URL parsers). /api/v1
is additive-only after freeze; the legacy-rewrite shim sunsets in ~2 releases
(owner decision) with removal tracked as a Phase-3 follow-up.
Docs: decisions.md 2026-07-13, api-conventions §1/§9, rest-api/spa-conventions/
blazor-route-parity/e2e-local/domain-model.
fixes #286
refs #197
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
180 lines
5.1 KiB
TypeScript
180 lines
5.1 KiB
TypeScript
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
import { ApiError, request } from './client';
|
|
import type { components } from './generated/v1';
|
|
|
|
export type DashboardChannel = components['schemas']['ChannelResponseModel'];
|
|
export type DashboardChannelState = components['schemas']['ChannelStateResponseModel'];
|
|
type DashboardHealthCheck = components['schemas']['HealthCheckResponseModel'];
|
|
type DashboardMediaSource = components['schemas']['MediaSourceResponseModel'];
|
|
type DashboardPlayouts = components['schemas']['PagedPlayoutsResponseModel'];
|
|
export type DashboardVersion = components['schemas']['CombinedVersion'];
|
|
|
|
export interface DashboardData {
|
|
channels: DashboardChannel[];
|
|
channelStates: DashboardChannelState[];
|
|
mediaSources: DashboardMediaSource[];
|
|
playouts: DashboardPlayouts;
|
|
}
|
|
|
|
export type DashboardQueryState =
|
|
| { data: DashboardData; error: null; status: 'success' }
|
|
| { data: null; error: string; status: 'error' }
|
|
| { data: null; error: null; status: 'loading' };
|
|
|
|
export type DashboardHealthQueryState =
|
|
| { checks: DashboardHealthCheck[]; error: null; refresh: () => void; status: 'success' }
|
|
| { checks: null; error: string; refresh: () => void; status: 'error' }
|
|
| { checks: null; error: null; refresh: () => void; status: 'loading' };
|
|
|
|
export type DashboardVersionQueryState =
|
|
| { error: null; status: 'success'; version: DashboardVersion }
|
|
| { error: string; status: 'error'; version: null }
|
|
| { error: null; status: 'loading'; version: null };
|
|
|
|
type DashboardHealthState =
|
|
| { checks: DashboardHealthCheck[]; error: null; status: 'success' }
|
|
| { checks: null; error: string; status: 'error' }
|
|
| { checks: null; error: null; status: 'loading' };
|
|
|
|
export async function getDashboardData(): Promise<DashboardData> {
|
|
const [channels, channelStates, mediaSources, playouts] = await Promise.all([
|
|
request<DashboardChannel[]>('/api/v1/channels'),
|
|
request<DashboardChannelState[]>('/api/v1/channels/state'),
|
|
request<DashboardMediaSource[]>('/api/v1/media-sources'),
|
|
request<DashboardPlayouts>('/api/v1/playouts')
|
|
]);
|
|
|
|
return { channels, channelStates, mediaSources, playouts };
|
|
}
|
|
|
|
export function getDashboardHealth(): Promise<DashboardHealthCheck[]> {
|
|
return request<DashboardHealthCheck[]>('/api/v1/health');
|
|
}
|
|
|
|
export function getDashboardVersion(): Promise<DashboardVersion> {
|
|
return request<DashboardVersion>('/api/v1/version');
|
|
}
|
|
|
|
export function useDashboardQuery(): DashboardQueryState {
|
|
const [state, setState] = useState<DashboardQueryState>({
|
|
data: null,
|
|
error: null,
|
|
status: 'loading'
|
|
});
|
|
|
|
useEffect(() => {
|
|
let active = true;
|
|
|
|
getDashboardData()
|
|
.then((data) => {
|
|
if (active) {
|
|
setState({ data, error: null, status: 'success' });
|
|
}
|
|
})
|
|
.catch((error: unknown) => {
|
|
if (active) {
|
|
setState({ data: null, error: messageFromError(error), status: 'error' });
|
|
}
|
|
});
|
|
|
|
return () => {
|
|
active = false;
|
|
};
|
|
}, []);
|
|
|
|
return state;
|
|
}
|
|
|
|
export function useDashboardHealthQuery(): DashboardHealthQueryState {
|
|
const [state, setState] = useState<DashboardHealthState>({
|
|
checks: null,
|
|
error: null,
|
|
status: 'loading'
|
|
});
|
|
|
|
const activeRef = useRef(true);
|
|
|
|
useEffect(() => {
|
|
activeRef.current = true;
|
|
|
|
return () => {
|
|
activeRef.current = false;
|
|
};
|
|
}, []);
|
|
|
|
const loadHealth = useCallback(() => {
|
|
getDashboardHealth()
|
|
.then((checks) => {
|
|
if (activeRef.current) {
|
|
setState({ checks, error: null, status: 'success' });
|
|
}
|
|
})
|
|
.catch((error: unknown) => {
|
|
if (activeRef.current) {
|
|
setState({ checks: null, error: messageFromError(error), status: 'error' });
|
|
}
|
|
});
|
|
}, []);
|
|
|
|
const refresh = useCallback(() => {
|
|
setState({ checks: null, error: null, status: 'loading' });
|
|
loadHealth();
|
|
}, [loadHealth]);
|
|
|
|
useEffect(() => {
|
|
loadHealth();
|
|
}, [loadHealth]);
|
|
|
|
if (state.status === 'success') {
|
|
return { checks: state.checks, error: null, refresh, status: 'success' };
|
|
}
|
|
|
|
if (state.status === 'error') {
|
|
return { checks: null, error: state.error, refresh, status: 'error' };
|
|
}
|
|
|
|
return { checks: null, error: null, refresh, status: 'loading' };
|
|
}
|
|
|
|
export function useDashboardVersionQuery(): DashboardVersionQueryState {
|
|
const [state, setState] = useState<DashboardVersionQueryState>({
|
|
error: null,
|
|
status: 'loading',
|
|
version: null
|
|
});
|
|
|
|
useEffect(() => {
|
|
let active = true;
|
|
|
|
getDashboardVersion()
|
|
.then((version) => {
|
|
if (active) {
|
|
setState({ error: null, status: 'success', version });
|
|
}
|
|
})
|
|
.catch((error: unknown) => {
|
|
if (active) {
|
|
setState({ error: messageFromError(error), status: 'error', version: null });
|
|
}
|
|
});
|
|
|
|
return () => {
|
|
active = false;
|
|
};
|
|
}, []);
|
|
|
|
return state;
|
|
}
|
|
|
|
function messageFromError(error: unknown): string {
|
|
if (error instanceof ApiError) {
|
|
return error.detail ?? error.message;
|
|
}
|
|
|
|
if (error instanceof Error) {
|
|
return error.message;
|
|
}
|
|
|
|
return 'Unable to load dashboard';
|
|
}
|