style: format satellite and launch provider modules

This commit is contained in:
Sameh Khamis committed 2026-09-11 21:22:41 -07:00
1 parent 9a4b98700e
commit 290afd808d
6 files changed
+163 -69

No files matched your search

+28 -8
View File
@@ -1,6 +1,9 @@
import path from 'node:path';
import { promises as fsp } from 'node:fs';
import { readResponseTextCapped, coalesceProxyRequest } from '../common/http.js';
import {
readResponseTextCapped,
coalesceProxyRequest,
} from '../common/http.js';
import { launchLibraryRecentUrl } from '../../../src/data/spaceProviderRequests.js';
export const LL2_CACHE_TTL_MS = 15 * 60_000;
@@ -19,7 +22,11 @@ export function rocketLaunchesProxy() {
const ttlMs = LL2_CACHE_TTL_MS;
const maxResponseBytes = 12 * 1024 * 1024;
const maxDiskCacheBytes = 24 * 1024 * 1024;
const cachePath = path.join(process.cwd(), '.gev-cache', 'launch-library-2-v2.3.json');
const cachePath = path.join(
process.cwd(),
'.gev-cache',
'launch-library-2-v2.3.json',
);
let cache = null;
let diskLoaded = false;
const inFlight = new Map();
@@ -29,13 +36,16 @@ export function rocketLaunchesProxy() {
diskLoaded = true;
try {
const stat = await fsp.stat(cachePath);
if (stat.size > maxDiskCacheBytes) throw new Error('cache file too large');
if (stat.size > maxDiskCacheBytes)
throw new Error('cache file too large');
const parsed = JSON.parse(await fsp.readFile(cachePath, 'utf8'));
if (Number.isFinite(parsed?.at) && typeof parsed?.body === 'string') {
const body = JSON.parse(parsed.body);
if (Array.isArray(body?.results)) cache = parsed;
}
} catch { /* first run or invalid cache */ }
} catch {
/* first run or invalid cache */
}
}
async function saveDiskCache(entry) {
@@ -70,7 +80,8 @@ export function rocketLaunchesProxy() {
throw error;
}
const parsed = JSON.parse(body);
if (!Array.isArray(parsed?.results)) throw new Error('malformed upstream response');
if (!Array.isArray(parsed?.results))
throw new Error('malformed upstream response');
const fresh = { at: Date.now(), body };
cache = fresh;
void saveDiskCache(fresh);
@@ -90,14 +101,23 @@ export function rocketLaunchesProxy() {
return;
}
const stale = cache;
const request = coalesceProxyRequest(inFlight, 'recent-launches', refreshUpstream);
const request = coalesceProxyRequest(
inFlight,
'recent-launches',
refreshUpstream,
);
try {
const fresh = await request.promise;
send(res, 200, fresh.body, request.shared ? 'INFLIGHT' : 'MISS');
} catch (error) {
// Log only a bounded status, never upstream bodies, URLs, or credentials.
const status = Number.isInteger(error?.upstreamStatus) ? error.upstreamStatus : 502;
if (!request.shared) console.warn(`[launch-library-proxy] refresh failed (HTTP ${status})${stale ? ' — serving stale cache' : ''}`);
const status = Number.isInteger(error?.upstreamStatus)
? error.upstreamStatus
: 502;
if (!request.shared)
console.warn(
`[launch-library-proxy] refresh failed (HTTP ${status})${stale ? ' — serving stale cache' : ''}`,
);
if (stale) {
send(res, 200, stale.body, 'STALE-ERROR');
return;