mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
21 lines
803 B
JavaScript
21 lines
803 B
JavaScript
import { normalizeEarthquakeSnapshot } from './records.js';
|
|
const API_URL =
|
|
'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson';
|
|
/** Request and validate a complete USGS snapshot before it can replace displayed events. */
|
|
export function createUsgsEarthquakeSource({
|
|
fetchImpl = (...args) => globalThis.fetch(...args),
|
|
} = {}) {
|
|
return {
|
|
async getSnapshot({ signal } = {}) {
|
|
signal?.throwIfAborted();
|
|
const response = await fetchImpl(API_URL, { signal });
|
|
if (!response.ok) throw new Error(`USGS HTTP ${response.status}`);
|
|
const payload = await response.json();
|
|
signal?.throwIfAborted();
|
|
const rows = normalizeEarthquakeSnapshot(payload);
|
|
if (!rows) throw new Error('Malformed USGS response');
|
|
return rows;
|
|
},
|
|
};
|
|
}
|