mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-15 15:52:21 +00:00
style: format satellite and launch provider modules
This commit is contained in:
1 parent
9a4b98700e
commit
290afd808d
6 files changed
+163
-69
No files matched your search
@@ -31,8 +31,11 @@ export function celestrakProxy() {
|
||||
async function readDisk(group) {
|
||||
try {
|
||||
const parsed = JSON.parse(await fsp.readFile(diskPath(group), 'utf8'));
|
||||
if (typeof parsed?.body === 'string' && Number.isFinite(parsed?.at)) return parsed;
|
||||
} catch { /* no disk cache yet */ }
|
||||
if (typeof parsed?.body === 'string' && Number.isFinite(parsed?.at))
|
||||
return parsed;
|
||||
} catch {
|
||||
/* no disk cache yet */
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -51,7 +54,10 @@ export function celestrakProxy() {
|
||||
signal: AbortSignal.timeout(20000),
|
||||
// CelesTrak 403s bulk groups (e.g. `active`) unless the request carries a
|
||||
// descriptive User-Agent with a contact point.
|
||||
headers: { 'User-Agent': 'gods-eye-view-celestrak-proxy/1.0 (+https://github.com/bilawalsidhu/gods-eye-view)' },
|
||||
headers: {
|
||||
'User-Agent':
|
||||
'gods-eye-view-celestrak-proxy/1.0 (+https://github.com/bilawalsidhu/gods-eye-view)',
|
||||
},
|
||||
});
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const body = await res.text();
|
||||
@@ -64,7 +70,9 @@ export function celestrakProxy() {
|
||||
name: 'celestrak-proxy',
|
||||
configureServer(server) {
|
||||
server.middlewares.use('/api/celestrak', async (req, res) => {
|
||||
const group = String(req.url || '').replace(/^\//, '').split('?')[0];
|
||||
const group = String(req.url || '')
|
||||
.replace(/^\//, '')
|
||||
.split('?')[0];
|
||||
if (!/^[a-z0-9-]+$/i.test(group)) {
|
||||
res.writeHead(400, { 'Content-Type': 'text/plain' });
|
||||
res.end('invalid group');
|
||||
@@ -75,7 +83,10 @@ export function celestrakProxy() {
|
||||
// went out routing into the catch's send): writeHead after headersSent
|
||||
// throws "Cannot set headers after they are sent".
|
||||
if (res.headersSent) return;
|
||||
res.writeHead(status, { 'Content-Type': 'text/plain', 'x-tle-cache': cacheStatus });
|
||||
res.writeHead(status, {
|
||||
'Content-Type': 'text/plain',
|
||||
'x-tle-cache': cacheStatus,
|
||||
});
|
||||
res.end(body);
|
||||
};
|
||||
try {
|
||||
@@ -91,17 +102,22 @@ export function celestrakProxy() {
|
||||
}
|
||||
// Stale or missing → refresh, single-flight per group.
|
||||
if (!inflight.has(group)) {
|
||||
inflight.set(group, fetchUpstream(group)
|
||||
.then(async (fresh) => {
|
||||
mem.set(group, fresh);
|
||||
await writeDisk(group, fresh);
|
||||
return fresh;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn('[celestrak-proxy] refresh failed — serving cache if any');
|
||||
return null;
|
||||
})
|
||||
.finally(() => inflight.delete(group)));
|
||||
inflight.set(
|
||||
group,
|
||||
fetchUpstream(group)
|
||||
.then(async (fresh) => {
|
||||
mem.set(group, fresh);
|
||||
await writeDisk(group, fresh);
|
||||
return fresh;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn(
|
||||
'[celestrak-proxy] refresh failed — serving cache if any',
|
||||
);
|
||||
return null;
|
||||
})
|
||||
.finally(() => inflight.delete(group)),
|
||||
);
|
||||
}
|
||||
const fresh = await inflight.get(group);
|
||||
if (fresh) {
|
||||
|
||||
Reference in new issue
Block a user