From f73f7ff266e181cc352c393b74f7d41b5e96694a Mon Sep 17 00:00:00 2001 From: GeorgeWebberley Date: Thu, 29 Jan 2026 11:04:41 +0100 Subject: [PATCH] Changed ISS API --- lib/db.ts | 2 +- scripts/update-space.ts | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/db.ts b/lib/db.ts index 391c410..985e69e 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -11,7 +11,7 @@ if (!fs.existsSync(dbDir)) { fs.mkdirSync(dbDir, { recursive: true }); } -const dbPath = path.resolve('/app/data/space_data.db'); +const dbPath = path.join(dbDir, 'space_data.db'); const db = new Database(dbPath); db.exec(` diff --git a/scripts/update-space.ts b/scripts/update-space.ts index 3c5badb..6c437af 100644 --- a/scripts/update-space.ts +++ b/scripts/update-space.ts @@ -12,12 +12,19 @@ const MY_ALT = 0; async function updateISSData() { console.log("🛰️ Fetching TLE data..."); - const response = await fetch('https://celestrak.org/NORAD/elements/gp.php?CATNR=25544&FORMAT=tle'); - const data = await response.text(); - const lines = data.split('\n').filter(line => line.trim().length > 0); + const response = await fetch('https://data.ivanstanojevic.me/api/tle/25544'); - const line1 = lines[1]; - const line2 = lines[2]; + if (!response.ok) { + throw new Error(`Mirror API Error: ${response.status}`); + } + + const data = await response.json(); + const line1 = data.line1; + const line2 = data.line2; + + if (!line1 || !line2) { + throw new Error("Invalid TLE data received from mirror"); + } const satrec = satellite.twoline2satrec(line1, line2); const observerGd = {