ADSB/AIS image proxy

This commit is contained in:
2026-07-03 18:48:20 -04:00
parent 4114a0adad
commit 1451145408
3 changed files with 52 additions and 2 deletions

View File

@@ -327,3 +327,38 @@ export async function getADSBRange() {
const j = await r.json();
return j?.actualRange?.last24h?.points || [];
}
export async function getADSBImage(icao) {
async function duckduckgo(query) {
async function getVqd(query) {
const res = await fetch(`https://duckduckgo.com/?q=${encodeURIComponent(query)}`, {
headers: { 'User-Agent': 'Mozilla/5.0' }
})
const html = await res.text()
const match = html.match(/vqd=['"]?([\d-]+)['"]?/)
return match?.[1]
}
const vqd = await getVqd(query)
if (!vqd) throw new Error('Could not get vqd token')
const url = `https://duckduckgo.com/i.js?q=${encodeURIComponent(query)}&o=json&vqd=${vqd}&f=,,,,,&p=1`
const data = await fetch(url, {headers: {'User-Agent': 'Mozilla/5.0', 'Referer': 'https://duckduckgo.com/'}}).then(resp => resp.json());
return data?.results?.[0]?.image || null;
}
let aircraft = (await adsbCache).find(a => a.icao?.toLowerCase() === icao?.toLowerCase());
if(!aircraft) aircraft = enrichAircraft({hex: icao});
if(!aircraft) return null;
const generic = duckduckgo(aircraft.model ? `${aircraft.manufacturer} ${aircraft.model}` : `${aircraft.aircraft} Aircraft`);
const specific = await fetch(`https://api.planespotters.net/pub/photos/hex/${icao.toLowerCase()}`).then(resp => resp.ok ? resp.json() : null);
let src;
if(specific?.photos?.[0]) src = specific?.photos?.[0];
else src = await generic;
if(!src) return null;
return fetch(src).then(resp => resp.blob());
}