Fixed image fetching

This commit is contained in:
2026-07-05 10:54:57 -04:00
parent 11012afbe9
commit 09a08d94aa
4 changed files with 10 additions and 3 deletions

View File

@@ -343,17 +343,22 @@ export async function getADSBImage(icao) {
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());
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;
}
const c = cfg();
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);
const specific = await fetch(`https://api.planespotters.net/pub/photos/hex/${icao.toLowerCase()}`,
{headers: {'User-Agent': `Personal ADSB Feeder + Dashboard (${c.EMAIL})`}}
).then(resp => resp.ok ? resp.json() : null);
let src;
if(specific?.photos?.[0]) src = specific.photos[0].thumbnail_large?.src || specific.photos[0].thumbnail?.src;

View File

@@ -11,6 +11,7 @@ export function cfg() {
PORT: process.env.PORT || 3000,
ADSB_URL: process.env.ADSB_URL || '',
DB_HOST: process.env.DB_HOST || 'http://localhost:8428',
EMAIL: process.env.EMAIL,
LATITUDE: parseFloat(process.env.LATITUDE || '0'),
LONGITUDE: parseFloat(process.env.LONGITUDE || '0'),
ALTITUDE: parseFloat(process.env.ALTITUDE || '0'),

View File

@@ -152,7 +152,7 @@ app.get('/api/icon/:icon', asyncHandler(async (req, res, next) => {
// res.json(filterFields(await getSpaceWeather(), fields));
// });
// ── ADSB Proxy ────────────────────────────────────────────────────────────────
// ── ADSB/AIS Proxy ────────────────────────────────────────────────────────────
app.get('/api/adsb', asyncHandler(async (req, res) => res.json(await getADSB())));
app.get('/api/adsb-image/:icao', asyncHandler(async (req, res) => {