| 57 | } |
| 58 | |
| 59 | private async refresh(): Promise<void> { |
| 60 | try { |
| 61 | const res = await fetch(this.url, { signal: AbortSignal.timeout(15000) }); |
| 62 | if (!res.ok) throw new Error(`HTTP ${res.status}`); |
| 63 | const tles = parseTle(await res.text()); |
| 64 | if (tles.length) { |
| 65 | this.tles = tles; |
| 66 | this.fetchedAt = Date.now(); |
| 67 | await mkdir(dirname(this.cachePath), { recursive: true }); |
| 68 | await writeFile( |
| 69 | this.cachePath, |
| 70 | JSON.stringify({ at: this.fetchedAt, tles }), |
| 71 | "utf8", |
| 72 | ); |
| 73 | console.log(`[tle] refreshed ${tles.length} satellites`); |
| 74 | } |
| 75 | } catch (err) { |
| 76 | console.error("[tle] refresh failed (using cache):", err instanceof Error ? err.message : err); |
| 77 | } |
| 78 | } |
| 79 | } |