// Every URL the UI talks to, in one place. A leaf module. const q = encodeURIComponent; async function getJson(url) { return (await fetch(url)).json(); } export const getConfig = () => getJson('/api/config'); export const getFiles = () => getJson('/api/files'); export const getStatus = () => getJson('/api/status'); export const getStorage = () => getJson('/api/storage'); export const analyze = (file, {margin, minGap, minDur}) => getJson(`/api/analyze?file=${q(file)}&margin=${q(margin)}` + `&min_gap=${q(minGap)}&min_duration=${q(minDur)}`); export async function deleteFile(file) { const r = await fetch('/api/files/' + q(file), {method: 'DELETE'}); if (!r.ok) { const d = await r.json().catch(() => ({})); throw new Error(d.error || r.statusText); } } export const clipUrl = (file, start, end) => `/api/clip?file=${q(file)}&start=${start.toFixed(1)}&end=${end.toFixed(1)}`; export const cutUrl = (file, start, end) => `/api/cut?file=${q(file)}&start=${start}&end=${end}`; export const streamUrl = file => '/stream/' + q(file); export const downloadUrl = file => '/download/' + q(file);