import type { Catalog, Preview } from './types'; async function request(url: string, signal?: AbortSignal): Promise { const response = await fetch(url, { signal, headers: { Accept: 'application/json' } }); if (!response.ok) { let message = `Request failed (${response.status})`; try { const body = await response.json(); message = typeof body.detail === 'string' ? body.detail : body.message || message; } catch { /* A proxy may return a non-JSON error page. */ } throw new Error(message); } return response.json() as Promise; } export const getCatalog = (refresh = false) => request(`/api/catalog${refresh ? '?refresh=true' : ''}`); export const getPreview = (id: string, signal?: AbortSignal) => request(`/api/assets/${encodeURIComponent(id)}/preview`, signal);