mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
refactor(radio): separate directory and playback components
This commit is contained in:
1 parent
ba7fda74d7
commit
41b3cc1705
30 files changed
+4488
-2795
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { DIRECTORY_ENDPOINT, RADIO_UUID_RE } from './policy.js';
|
||||
|
||||
/** Supply directory metadata and click reporting; audio stays with the broadcaster. */
|
||||
export function createRadioSource({
|
||||
fetchImpl = (...args) => globalThis.fetch(...args),
|
||||
} = {}) {
|
||||
return {
|
||||
async getDirectory({ signal } = {}) {
|
||||
signal?.throwIfAborted();
|
||||
const response = await fetchImpl(DIRECTORY_ENDPOINT, { signal });
|
||||
if (!response.ok)
|
||||
throw new Error(`Radio directory returned ${response.status}`);
|
||||
const body = await response.json();
|
||||
signal?.throwIfAborted();
|
||||
return body;
|
||||
},
|
||||
async recordClick(id, { signal } = {}) {
|
||||
if (typeof id !== 'string' || !RADIO_UUID_RE.test(id))
|
||||
throw new Error('Invalid radio station id');
|
||||
signal?.throwIfAborted();
|
||||
const response = await fetchImpl(
|
||||
`/api/radio/click/${encodeURIComponent(id)}`,
|
||||
{
|
||||
method: 'POST',
|
||||
signal,
|
||||
},
|
||||
);
|
||||
signal?.throwIfAborted();
|
||||
if (!response.ok)
|
||||
throw new Error(`Radio click returned ${response.status}`);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user