mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 18:34:02 +00:00
A sweep for the same pattern found more answers presented as current and complete: launches and satellite orbits served from a stale proxy cache, a regional aircraft fallback read as worldwide, license plate cameras trimmed or partly loaded, and a radio directory of popular stations read as every station. The launch and satellite sources now report the proxies' stale markers, and each answer says what it covers.
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
/** Read launch records and their optional active-orbit catalog with explicit cancellation. */
|
|
export function createLaunchSource({
|
|
fetchImpl = (...args) => globalThis.fetch(...args),
|
|
} = {}) {
|
|
/** The launch payload, and whether the proxy served it from a stale cache. */
|
|
async function getLaunchSnapshot({ signal } = {}) {
|
|
signal?.throwIfAborted();
|
|
const response = await fetchImpl('/api/launches', { signal });
|
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
const payload = await response.json();
|
|
signal?.throwIfAborted();
|
|
if (!Array.isArray(payload) && !Array.isArray(payload?.results))
|
|
throw new Error('Malformed launch snapshot');
|
|
return {
|
|
payload,
|
|
stale: response.headers?.get?.('x-gev-cache') === 'STALE-ERROR',
|
|
};
|
|
}
|
|
return {
|
|
getLaunchSnapshot,
|
|
async getLaunches(options) {
|
|
return (await getLaunchSnapshot(options)).payload;
|
|
},
|
|
async getActiveTle({ signal } = {}) {
|
|
signal?.throwIfAborted();
|
|
const response = await fetchImpl('/api/celestrak/active', { signal });
|
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
const text = await response.text();
|
|
signal?.throwIfAborted();
|
|
return text;
|
|
},
|
|
};
|
|
}
|