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 { return request('/api/v1/filler-presets').then(sortByName); } export function getWatermarks(): Promise { return request('/api/v1/watermarks').then(sortByName); } // Pass refresh=true to first re-sync the on-disk graphics element definitions into the database // (matching legacy Blazor's RefreshGraphicsElements-before-list) so newly added files appear. export function getGraphicsElements(refresh = false): Promise { const url = refresh ? '/api/v1/graphics-elements?refresh=true' : '/api/v1/graphics-elements'; return request(url).then(sortByName); } export function getFFmpegProfiles(): Promise { return request('/api/v1/ffmpeg/profiles').then(sortByName); } function sortByName(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; }