diff --git a/server/src/adsb.mjs b/server/src/adsb.mjs index 6aa3ee1..800b061 100644 --- a/server/src/adsb.mjs +++ b/server/src/adsb.mjs @@ -190,7 +190,11 @@ async function scrapeHexDatabase(icao) { const resp = await fetch(url); if (!resp.ok) return null; - const $ = cheerio.load(await resp.text()); + const html = await resp.text(); + const tableMatch = html.match(//i); + if (!tableMatch) return null; + + const $ = cheerio.load(tableMatch[0]); const row = $('tr').filter((_, el) => $(el).text().toLowerCase().includes(icao.toLowerCase())).first(); if (!row.length) return null; @@ -229,7 +233,7 @@ export async function enrichAircraft(a) { // 1. Check own DB first const row = db.prepare('SELECT * FROM aircraft WHERE icao = ?').get(icao); - if(row?.manufacturer && row?.model) return { ...a, ...row, type: classifyAircraft(row) }; + if(row?.aircraft) return { ...a, ...row, type: classifyAircraft(row) }; // 2. Race the two external sources if(noRecord.includes(icao)) return { icao, ...a, type: 'unknown' };