- Introduced a new HTML documentation page for the oradio API, including a JavaScript file to handle dynamic content and API requests. - Added a CSS file for styling the documentation page. - Implemented an underground station importer script that fetches data from Radio-Browser and writes it to a JSON file. - Created a stats module to compute and manage vote and play statistics for radio stations. - Added a polyfill for modulepreload to ensure compatibility with older browsers.
22 lines
772 B
JavaScript
22 lines
772 B
JavaScript
async function http(method, path, body) {
|
|
const res = await fetch(path, {
|
|
method,
|
|
credentials: 'same-origin',
|
|
headers: body ? { 'Content-Type': 'application/json' } : {},
|
|
body: body ? JSON.stringify(body) : undefined
|
|
});
|
|
if (res.status === 204) return null;
|
|
const ct = res.headers.get('content-type') || '';
|
|
const data = ct.includes('json') ? await res.json() : await res.text();
|
|
if (!res.ok) throw Object.assign(new Error(data?.error || res.statusText), { status: res.status, data });
|
|
return data;
|
|
}
|
|
|
|
export const api = {
|
|
get: (p) => http('GET', p),
|
|
post: (p, b) => http('POST', p, b),
|
|
put: (p, b) => http('PUT', p, b),
|
|
patch: (p, b) => http('PATCH', p, b),
|
|
del: (p) => http('DELETE', p)
|
|
};
|