Fixed image fetching
This commit is contained in:
1
.env
1
.env
@@ -1,3 +1,4 @@
|
|||||||
|
EMAIL=
|
||||||
ALTITUDE=
|
ALTITUDE=
|
||||||
LATITUDE=
|
LATITUDE=
|
||||||
LONGITUDE=
|
LONGITUDE=
|
||||||
|
|||||||
@@ -343,17 +343,22 @@ export async function getADSBImage(icao) {
|
|||||||
if (!vqd) throw new Error('Could not get vqd token')
|
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 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;
|
return data?.results?.[0]?.image || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const c = cfg();
|
||||||
let aircraft = (await adsbCache).find(a => a.icao?.toLowerCase() === icao?.toLowerCase());
|
let aircraft = (await adsbCache).find(a => a.icao?.toLowerCase() === icao?.toLowerCase());
|
||||||
if(!aircraft) aircraft = enrichAircraft({hex: icao});
|
if(!aircraft) aircraft = enrichAircraft({hex: icao});
|
||||||
if(!aircraft) return null;
|
if(!aircraft) return null;
|
||||||
|
|
||||||
const generic = duckduckgo(aircraft.model ? `${aircraft.manufacturer} ${aircraft.model}` : `${aircraft.aircraft} Aircraft`);
|
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;
|
let src;
|
||||||
if(specific?.photos?.[0]) src = specific.photos[0].thumbnail_large?.src || specific.photos[0].thumbnail?.src;
|
if(specific?.photos?.[0]) src = specific.photos[0].thumbnail_large?.src || specific.photos[0].thumbnail?.src;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export function cfg() {
|
|||||||
PORT: process.env.PORT || 3000,
|
PORT: process.env.PORT || 3000,
|
||||||
ADSB_URL: process.env.ADSB_URL || '',
|
ADSB_URL: process.env.ADSB_URL || '',
|
||||||
DB_HOST: process.env.DB_HOST || 'http://localhost:8428',
|
DB_HOST: process.env.DB_HOST || 'http://localhost:8428',
|
||||||
|
EMAIL: process.env.EMAIL,
|
||||||
LATITUDE: parseFloat(process.env.LATITUDE || '0'),
|
LATITUDE: parseFloat(process.env.LATITUDE || '0'),
|
||||||
LONGITUDE: parseFloat(process.env.LONGITUDE || '0'),
|
LONGITUDE: parseFloat(process.env.LONGITUDE || '0'),
|
||||||
ALTITUDE: parseFloat(process.env.ALTITUDE || '0'),
|
ALTITUDE: parseFloat(process.env.ALTITUDE || '0'),
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ app.get('/api/icon/:icon', asyncHandler(async (req, res, next) => {
|
|||||||
// res.json(filterFields(await getSpaceWeather(), fields));
|
// 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', asyncHandler(async (req, res) => res.json(await getADSB())));
|
||||||
app.get('/api/adsb-image/:icao', asyncHandler(async (req, res) => {
|
app.get('/api/adsb-image/:icao', asyncHandler(async (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user