feat(aircraft): planespotters.net photo in aircraft popup
Add planespotters.net latest-photo lookup for ADS-B aircraft. - app/live_layers.py: fetch_planespotters_photo() (hex preferred, reg fallback) + _normalize_planespotter_photo(); 24h TTL cache (their ToS cap). - app/main.py: GET /api/aircraft/photo?hex=...|reg=... (422/404/502). - app/static/index.html: .ps-photo block in ADS-B popup; lazy load on popupopen; thumbnail links to photo page + photographer credit. Server-side proxy, not browser fetch(): planespotters 403s any request carrying an Origin header (every browser fetch() sends one). The thumbnail binary is loaded by the browser straight from their CDN, never re-hosted. Tests: 4 unit + 4 API contract (38 pass in the two files).
This commit is contained in:
parent
e568d013ca
commit
665aaec22f
5 changed files with 228 additions and 4 deletions
|
|
@ -75,3 +75,35 @@ def test_vessels_subscribe_rejects_bad_bbox():
|
|||
assert resp.status_code == 422, bad
|
||||
# Explicit null bbox is the "reset to env default" path (still 200).
|
||||
assert asyncio.run(_post("/api/vessels/subscribe", {"bbox": None})).status_code == 200
|
||||
|
||||
|
||||
def test_aircraft_photo_requires_hex_or_reg():
|
||||
assert asyncio.run(_get("/api/aircraft/photo")).status_code == 422
|
||||
|
||||
|
||||
def test_aircraft_photo_rejects_bad_hex():
|
||||
# hex must be exactly 6 hex chars
|
||||
resp = asyncio.run(_get("/api/aircraft/photo?hex=xyz1234"))
|
||||
assert resp.status_code == 422
|
||||
|
||||
|
||||
def test_aircraft_photo_returns_photo(monkeypatch):
|
||||
async def fake(hex_code=None, reg=None):
|
||||
return {"id": "1", "src": "https://t.plnspttrs.net/a_280.jpg",
|
||||
"link": "https://www.planespotters.net/photo/1/x", "photographer": "A"}
|
||||
|
||||
monkeypatch.setattr("main.fetch_planespotters_photo", fake)
|
||||
resp = asyncio.run(_get("/api/aircraft/photo?hex=e8027e"))
|
||||
assert resp.status_code == 200
|
||||
body = resp.json()
|
||||
assert body["src"].startswith("https://t.plnspttrs.net/")
|
||||
assert "max-age" in (resp.headers.get("cache-control") or "").lower()
|
||||
|
||||
|
||||
def test_aircraft_photo_404_when_no_photo(monkeypatch):
|
||||
async def fake(hex_code=None, reg=None):
|
||||
return None
|
||||
|
||||
monkeypatch.setattr("main.fetch_planespotters_photo", fake)
|
||||
resp = asyncio.run(_get("/api/aircraft/photo?reg=D-ABCD"))
|
||||
assert resp.status_code == 404
|
||||
|
|
|
|||
Loading…
Reference in a new issue