Review SHOULD-FIX (#145): the SPA graphics picker could go stale because Blazor ran RefreshGraphicsElements (disk->DB sync) before listing, while the API endpoint never refreshed — a newly added .yml would not appear. GET /api/graphics-elements?refresh=true now sends RefreshGraphicsElements before the list query; default false leaves existing callers untouched. The playback troubleshooting screen passes refresh=true. Controller tests cover refresh-iff-true ordering; regenerated OpenAPI v1.json (endpoint index and generated TS schemas unchanged - query params are not part of either). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
53 lines
1.8 KiB
TypeScript
53 lines
1.8 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);
|
|
}
|
|
|
|
// 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<GraphicsElement[]> {
|
|
const url = refresh ? '/api/graphics-elements?refresh=true' : '/api/graphics-elements';
|
|
return request<GraphicsElement[]>(url).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;
|
|
}
|