mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
30 lines
874 B
JavaScript
30 lines
874 B
JavaScript
/** Construct the existing live-fire endpoint without making a request. */
|
|
export function createFirmsSource({
|
|
fetchImpl = (...args) => globalThis.fetch(...args),
|
|
} = {}) {
|
|
return {
|
|
async getSnapshot({ signal } = {}) {
|
|
signal?.throwIfAborted();
|
|
const response = await fetchImpl('/api/firms', {
|
|
signal,
|
|
cache: 'no-store',
|
|
});
|
|
let payload;
|
|
try {
|
|
payload = await response.json();
|
|
} catch {
|
|
/* status below remains authoritative */
|
|
}
|
|
signal?.throwIfAborted();
|
|
if (!response.ok) {
|
|
if (response.status === 503 && payload?.error === 'no_key')
|
|
return { keyRequired: true };
|
|
throw new Error(`FIRMS HTTP ${response.status}`);
|
|
}
|
|
if (!Array.isArray(payload?.fires))
|
|
throw new Error('Malformed fire snapshot');
|
|
return payload;
|
|
},
|
|
};
|
|
}
|