Files
ersatztv/web/src/api/pickers.ts
T
timothyandClaude Fable 5 8e11362360 feat(web): Dialog primitive + Channel Builder API modules (refs #89)
- components/overlay.tsx: first Dialog/ConfirmDialog (portal, esc/backdrop
  close, scroll lock, aria wiring, reduced-motion aware) + 7 tests
- api: libraryBrowse, channelTemplates (default 404->null), artwork upload
  (multipart /api/artwork/uploads), pickers (client-sorted lists incl.
  /api/ffmpeg/profiles), createChannelFromLineup in channels.ts
- schedules.ts now sources filler/watermark fetchers from pickers.ts
  (avoids duplicate barrel exports)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 22:07:36 +02:00

50 lines
1.6 KiB
TypeScript

import { ApiError, request } from './client';
import type { components } from './generated/v1';
export type FillerPreset = components['schemas']['FillerPresetResponseModel'];
export type Watermark = components['schemas']['WatermarkResponseModel'];
export type GraphicsElement = components['schemas']['GraphicsElementResponseModel'];
export type FFmpegProfile = components['schemas']['FFmpegFullProfileResponseModel'];
export function getFillerPresets(): Promise<FillerPreset[]> {
return request<FillerPreset[]>('/api/filler-presets').then(sortByName);
}
export function getWatermarks(): Promise<Watermark[]> {
return request<Watermark[]>('/api/watermarks').then(sortByName);
}
export function getGraphicsElements(): Promise<GraphicsElement[]> {
return request<GraphicsElement[]>('/api/graphics-elements').then(sortByName);
}
export function getFFmpegProfiles(): Promise<FFmpegProfile[]> {
return request<FFmpegProfile[]>('/api/ffmpeg/profiles').then(sortByName);
}
function sortByName<T extends { name: null | string }>(items: T[]): T[] {
return [...items].sort((left, right) => {
if (left.name == null) {
return right.name == null ? 0 : 1;
}
if (right.name == null) {
return -1;
}
return left.name.localeCompare(right.name, undefined, { sensitivity: 'base' });
});
}
export function messageFromPickersError(error: unknown, fallback = 'Unable to load picker data'): string {
if (error instanceof ApiError) {
return error.detail ?? error.message;
}
if (error instanceof Error) {
return error.message;
}
return fallback;
}