mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
feat(flights): show the tracked aircraft's Planespotters photo in Contacts
Tracking a civil flight asks Planespotters for that aircraft's photo, once per aircraft, straight from the browser. The CONTEXT panel's CONTACTS view shows it under the flight's name with the photographer's credit, as a plain link to the photo's page. Only images on plnspttrs.net and pages on www.planespotters.net are ever shown or linked. Military aircraft and a converted TR-3B are never looked up. Flight lookups (type, route, photo) whose source failed temporarily are asked again after a 60-second cool-down; an answer, found or not, and a permanent refusal stay final for the session. A route belongs to the callsign it was looked up for, so a callsign change drops the old route. Browser QA scripts that track a flight answer the photo lookup themselves, so they never call the third party.
This commit is contained in:
1 parent
78c5b6c245
commit
1a8defbfc8
52 files changed
+1781
-46
No files matched your search
@@ -11,10 +11,37 @@ import {
|
||||
readsbIdentities,
|
||||
} from './aircraft.js';
|
||||
import { normalizeVesselTrack, vesselSnapshot } from './vessels.js';
|
||||
import { parsePlanespottersPhoto } from '../../data/planespottersPhoto.js';
|
||||
|
||||
const defaultFetch = (...args) => globalThis.fetch(...args);
|
||||
const header = (response, name) => response.headers?.get?.(name);
|
||||
|
||||
/** Planespotters' public photo lookup, called straight from the browser (it
|
||||
* answers with `access-control-allow-origin: *`). */
|
||||
const PLANESPOTTERS_PHOTOS = 'https://api.planespotters.net/pub/photos/hex/';
|
||||
/** A photo is decoration: a slow answer gives up rather than hold an
|
||||
* enrichment slot. */
|
||||
const PHOTO_TIMEOUT_MS = 8000;
|
||||
|
||||
/** The tracked plane's Planespotters photo, read and host-checked. */
|
||||
async function planespottersPhoto(fetchImpl, hex, signal) {
|
||||
const id = String(hex || '').toLowerCase();
|
||||
if (!/^[0-9a-f]{6}$/.test(id))
|
||||
throw new LiveSourceError('unsupported', 'Enrichment unavailable');
|
||||
const timeout = AbortSignal.timeout(PHOTO_TIMEOUT_MS);
|
||||
const { response, payload } = await readResponse(
|
||||
fetchImpl,
|
||||
PLANESPOTTERS_PHOTOS + id,
|
||||
{
|
||||
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
||||
credentials: 'omit',
|
||||
},
|
||||
'Planespotters',
|
||||
);
|
||||
if (!response.ok) throw httpError(response, 'Planespotters');
|
||||
return parsePlanespottersPhoto(payload);
|
||||
}
|
||||
|
||||
function openSkyError(response) {
|
||||
const error = httpError(response, 'Flights');
|
||||
const mode = String(
|
||||
@@ -106,6 +133,8 @@ export function createFlightSource({
|
||||
};
|
||||
},
|
||||
async getEnrichment(query, { signal } = {}) {
|
||||
if (query.kind === 'photo')
|
||||
return planespottersPhoto(fetchImpl, query.id, signal);
|
||||
if (!['type', 'route'].includes(query.kind))
|
||||
throw new LiveSourceError('unsupported', 'Enrichment unavailable');
|
||||
const { response, payload } = await readResponse(
|
||||
|
||||
Reference in new issue
Block a user