feat(airtrail): use the AirTrail /api/v1 routes, and keep the legacy routes

AirTrail 3.13 adds /api/v1 and marks the /api/flight/* routes as
deprecated. TREK now asks the public discovery document GET /api/v1
and uses v1 when the instance has it. It uses the legacy routes for
an older instance. The client methods keep their signatures, and the
sync hash stays the same, so a linked flight does not sync again
when an instance changes to v1.

The probe cache holds only a clear answer: 200 with the discovery
document gives v1, and 404 gives legacy. The cache is per AirTrail
URL, for 10 minutes. A timeout, a 5xx or a network error fails that
call only. A 401, a 403 or a page that is not the discovery document
uses legacy for that call only. A 404 for one flight makes the client
ask the probe again before it reports the flight as deleted.

A missing scope gives AirtrailScopeError, which names the scope. It
does not unlink a flight. The API key hint and the help step list
the scopes for read and for write-back, in all languages.

Each new request goes through safeFetch, with the SSRF guard, the
timeout and the size cap. The flight list reads pages of 100 and
fails above 50 pages. A failed list unlinks nothing.

airtrail-v1.ts translates between the v1 shapes and the legacy
shapes. A write-back looks up the airport, airline and aircraft ids,
and changes each local time to a UTC instant in the zone of its own
airport. It writes each instant in the +00:00 form of the legacy
save, because AirTrail stores the string as it gets it and the sync
hash reads that string.

The tests cover both APIs over HTTP, the probe cache rules, the sync
hash on a switch and on a save, the page limit, the scope error, and
the UTC conversion across midnight, the date line and daylight-saving
changes.
This commit is contained in:
aaronspruit
2026-11-16 18:52:57 -08:00
committed by Maurice
parent 3e0a2ef8ed
commit 76ff6e15b1
61 changed files with 1442 additions and 74 deletions
+1 -1
View File
@@ -3975,7 +3975,7 @@ const help: TranslationStrings = {
'help.guide.dashboard-widgets.step.3': '“รีเซ็ตเป็นค่าเริ่มต้น” ใต้การ์ดจะคืนแท็บ “ลักษณะที่ปรากฏ” ทั้งหมดเป็นค่าเดิม',
'help.guide.web-push-device.result': 'การ์ดจะแสดง “เปิดอยู่สำหรับอุปกรณ์นี้” และเหตุการณ์ที่เปิดไว้ใต้ “พุช” จะส่งมาถึงแม้ปิด TREK อยู่',
'help.guide.connect-airtrail.step.1':
'ใต้ “การเชื่อมต่อ” หา AirTrail แล้วกรอก “URL ของอินสแตนซ์” และคีย์ API คุณสร้างคีย์ได้ใน AirTrail ที่ “การตั้งค่า” แล้วไปที่ความปลอดภัย',
'ใต้ “การเชื่อมต่อ” หา AirTrail แล้วกรอก “URL ของอินสแตนซ์” และคีย์ API คุณสร้างคีย์ได้ใน AirTrail ที่ “การตั้งค่า” แล้วไปที่ความปลอดภัย หากคุณสร้างคีย์ใน AirTrail 3.13 ขึ้นไป คีย์ต้องมีขอบเขต flight.read.own เพื่ออ่าน หากต้องการเขียนการเปลี่ยนแปลงกลับ คีย์ต้องมี flight.update.own, flight.passengers.manage.own, reference_data.read และ profile.read ด้วย',
'help.guide.connect-dawarich.step.1':
'ใต้ “การเชื่อมต่อ” หา Dawarich แล้วกรอก “ที่อยู่ของอินสแตนซ์” และคีย์ API จาก Dawarich ที่ “บัญชี” แล้วไปที่ “คีย์ API”',
'help.guide.tour-connect-wanderer.step.1':
+2 -1
View File
@@ -395,7 +395,8 @@ const settings: TranslationStrings = {
'settings.airtrail.url': 'URL ของอินสแตนซ์',
'settings.airtrail.apiKey': 'คีย์เอพีไอ',
'settings.airtrail.apiKeyPlaceholder': 'คีย์ API ของผู้ถือ',
'settings.airtrail.apiKeyHint': 'สร้างใน AirTrail ภายใต้การตั้งค่า → ความปลอดภัย จัดเก็บแบบเข้ารหัส',
'settings.airtrail.apiKeyHint':
'สร้างใน AirTrail ภายใต้การตั้งค่า → ความปลอดภัย จัดเก็บแบบเข้ารหัส หากคุณสร้างคีย์ใน AirTrail 3.13 ขึ้นไป คีย์ต้องมีขอบเขต flight.read.own เพื่ออ่าน หากต้องการเขียนการเปลี่ยนแปลงกลับ คีย์ต้องมี flight.update.own, flight.passengers.manage.own, reference_data.read และ profile.read ด้วย',
'settings.airtrail.allowInsecureTls': 'อนุญาตใบรับรองที่ลงนามด้วยตนเอง',
'settings.airtrail.allowInsecureTlsHint': 'เปิดใช้งานสำหรับอินสแตนซ์ที่เชื่อถือได้บนเครือข่ายของคุณเองเท่านั้น',
'settings.airtrail.writeBack': 'เขียนการเปลี่ยนแปลงกลับไปที่ AirTrail',