mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22: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
@@ -412,3 +412,77 @@ test('squawks are validated and omitted OpenSky status differs from an explicit
|
||||
assert.equal(quiet.squawk, null);
|
||||
assert.equal(quiet.emergency, null);
|
||||
});
|
||||
|
||||
test('a photo enrichment asks Planespotters directly and returns the checked photo', async () => {
|
||||
const requests = [];
|
||||
const source = createFlightSource({
|
||||
fetchImpl: async (url, init) => {
|
||||
requests.push({ url, init });
|
||||
return response({
|
||||
photos: [
|
||||
{
|
||||
thumbnail_large: {
|
||||
src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_280.jpg',
|
||||
size: { width: 420, height: 280 },
|
||||
},
|
||||
link: 'https://www.planespotters.net/photo/1745410/x?utm_source=api',
|
||||
photographer: 'Jan Seler',
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
const signal = new AbortController().signal;
|
||||
const photo = await source.getEnrichment(
|
||||
{ kind: 'photo', id: 'a0f1bb' },
|
||||
{ signal },
|
||||
);
|
||||
assert.equal(
|
||||
requests[0].url,
|
||||
'https://api.planespotters.net/pub/photos/hex/a0f1bb',
|
||||
);
|
||||
assert.ok(requests[0].init.signal, 'the request is cancellable');
|
||||
assert.equal(requests[0].init.credentials, 'omit');
|
||||
assert.deepEqual(photo, {
|
||||
found: true,
|
||||
src: 'https://t.plnspttrs.net/33043/1745410_822dfe330c_280.jpg',
|
||||
width: 420,
|
||||
height: 280,
|
||||
photographer: 'Jan Seler',
|
||||
link: 'https://www.planespotters.net/photo/1745410/x?utm_source=api',
|
||||
});
|
||||
});
|
||||
|
||||
test('a photo enrichment reads an empty answer as no photo and refuses a bad hex', async () => {
|
||||
let calls = 0;
|
||||
const source = createFlightSource({
|
||||
fetchImpl: async (_url, _init) => {
|
||||
calls++;
|
||||
return response({ photos: [] });
|
||||
},
|
||||
});
|
||||
assert.deepEqual(
|
||||
await source.getEnrichment({ kind: 'photo', id: 'a0f1bb' }),
|
||||
{ found: false },
|
||||
);
|
||||
await assert.rejects(source.getEnrichment({ kind: 'photo', id: '../x' }), {
|
||||
code: 'unsupported',
|
||||
});
|
||||
assert.equal(calls, 1);
|
||||
});
|
||||
|
||||
test('a photo enrichment outage rejects without echoing the body', async () => {
|
||||
for (const status of [403, 429, 502]) {
|
||||
const source = createFlightSource({
|
||||
fetchImpl: async () => response({ error: 'sensitive' }, {}, status),
|
||||
});
|
||||
await assert.rejects(
|
||||
source.getEnrichment({ kind: 'photo', id: 'a0f1bb' }),
|
||||
(error) => {
|
||||
assert.equal(error.status, status);
|
||||
assert.equal(error.message.includes('sensitive'), false);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user