import { cfg } from './config.mjs' import { writeFile, readFile } from 'fs/promises' import { existsSync } from 'fs' import { resolve, dirname } from 'path' import { fileURLToPath } from 'url' const DIR = dirname(fileURLToPath(import.meta.url)) const SHAPES_PATH = resolve(DIR, 'public', 'aircraft.js') export async function getShapes() { JSON.parse(await readFile(SHAPES_PATH, 'utf8')) } export async function getAirTraffic() { const { ADSB_URL } = cfg() if (!ADSB_URL) return { data: [] } const r = await fetch(`${ADSB_URL}/re-api/?all`) const j = await r.json() return { data: j.aircraft || [] } } export async function getAirTrafficHistory(icao) { const { ADSB_URL } = cfg() if (!ADSB_URL) return { history: [] } const r = await fetch(`${ADSB_URL}/re-api/?trace&icao=${icao}`) const j = await r.json() const history = (j.trace || []).map(t => ({ latitude: t[1], longitude: t[2], altitude: t[3] || 0, })) return { history } }