Come up with a common base class for backwards-compatibility translation wrappers between the different API versions #143

This commit is contained in:
Ian Renton
2026-09-24 21:47:09 +01:00
parent 0ce3ca8d29
commit 81166dccab
9 changed files with 419 additions and 459 deletions
+68 -21
View File
@@ -17,6 +17,34 @@ from core.data_providers import DATA_PROVIDERS
from core.data_store import DATA_STORE
from webserver.handlers.api.addspot import APISpotHandler
from webserver.handlers.api.alerts import APIAlertsHandler, APIAlertsStreamHandler
from webserver.handlers.api.compatibility.v1_compatibility import (
V1APIAlertsHandler,
V1APIAlertsStreamHandler,
V1APIDxStatsHandler,
V1APILookupCallHandler,
V1APILookupGridHandler,
V1APILookupSigRefHandler,
V1APIOptionsHandler,
V1APISolarConditionsHandler,
V1APISpotHandler,
V1APISpotsHandler,
V1APISpotsStreamHandler,
V1APIStatusHandler,
)
from webserver.handlers.api.compatibility.v2_compatibility import (
V2APIAlertsHandler,
V2APIAlertsStreamHandler,
V2APIDxStatsHandler,
V2APILookupCallHandler,
V2APILookupGridHandler,
V2APILookupSigRefHandler,
V2APIOptionsHandler,
V2APISolarConditionsHandler,
V2APISpotHandler,
V2APISpotsHandler,
V2APISpotsStreamHandler,
V2APIStatusHandler,
)
from webserver.handlers.api.dxstats import APIDxStatsHandler
from webserver.handlers.api.lookups import (
APILookupActivityRefHandler,
@@ -27,19 +55,6 @@ from webserver.handlers.api.options import APIOptionsHandler
from webserver.handlers.api.solar_conditions import APISolarConditionsHandler
from webserver.handlers.api.spots import APISpotsHandler, APISpotsStreamHandler
from webserver.handlers.api.status import APIStatusHandler
from webserver.handlers.api.v1_addspot import V1APISpotHandler
from webserver.handlers.api.v1_compatability import V1RedirectHandler
from webserver.handlers.api.v1_spots import V1APISpotsHandler, V1APISpotsStreamHandler
from webserver.handlers.api.v2_compatibility import (
V2APIAlertsHandler,
V2APIAlertsStreamHandler,
V2APILookupSigRefHandler,
V2APIOptionsHandler,
V2APISpotHandler,
V2APISpotsHandler,
V2APISpotsStreamHandler,
V2APIStatusHandler,
)
from webserver.handlers.manifesthandler import ManifestHandler
from webserver.handlers.metrics import PrometheusMetricsHandler
from webserver.handlers.pagetemplate import PageTemplateHandler
@@ -169,7 +184,7 @@ class WebServer:
),
]
# v2 API compatibility routes
# v2 API compatibility routes. Translation wrappers convert data to the v3 format and back.
v2_compat_routes = [
(
r"/api/v2/spots",
@@ -193,12 +208,12 @@ class WebServer:
),
(
r"/api/v2/solar",
APISolarConditionsHandler,
V2APISolarConditionsHandler,
{"solar_conditions": self._data_store.solar_conditions.get()},
),
(
r"/api/v2/dxstats",
APIDxStatsHandler,
V2APIDxStatsHandler,
{"spots": self._data_store.spots},
),
(
@@ -211,9 +226,9 @@ class WebServer:
V2APIStatusHandler,
{"status_data": self._data_store.status.get()},
),
(r"/api/v2/lookup/call", APILookupCallHandler),
(r"/api/v2/lookup/call", V2APILookupCallHandler),
(r"/api/v2/lookup/sigref", V2APILookupSigRefHandler),
(r"/api/v2/lookup/grid", APILookupGridHandler),
(r"/api/v2/lookup/grid", V2APILookupGridHandler),
(
r"/api/v2/spot",
V2APISpotHandler,
@@ -224,27 +239,59 @@ class WebServer:
),
]
# v1 API redirects. Most v1 enpoints are unchanged in v2, and are proxied to the v2 API (which in turn is
# translated from v3). The ones that have the major breaking changes get a bespoke handler.
# Translation wrappers convert data to the v3 format and back.
v1_compat_routes = [
(
r"/api/v1/spots",
V1APISpotsHandler,
{"spots": self._data_store.spots},
),
(
r"/api/v1/alerts",
V1APIAlertsHandler,
{"alerts": self._data_store.alerts},
),
(
r"/api/v1/spots/stream",
V1APISpotsStreamHandler,
{"sse_spot_broadcaster": self._spot_broadcaster},
),
(
r"/api/v1/alerts/stream",
V1APIAlertsStreamHandler,
{"sse_alert_broadcaster": self._alert_broadcaster},
),
(
r"/api/v1/solar",
V1APISolarConditionsHandler,
{"solar_conditions": self._data_store.solar_conditions.get()},
),
(
r"/api/v1/dxstats",
V1APIDxStatsHandler,
{"spots": self._data_store.spots},
),
(
r"/api/v1/options",
V1APIOptionsHandler,
{"status_data": self._data_store.status.get()},
),
(
r"/api/v1/status",
V1APIStatusHandler,
{"status_data": self._data_store.status.get()},
),
(r"/api/v1/lookup/call", V1APILookupCallHandler),
(r"/api/v1/lookup/sigref", V1APILookupSigRefHandler),
(r"/api/v1/lookup/grid", V1APILookupGridHandler),
(
r"/api/v1/spot",
V1APISpotHandler,
{
"spots": self._data_store.spots,
"spot_providers": self._data_providers,
},
),
(r"/api/v1/(.*)", V1RedirectHandler),
]
# If in API-only mode, serve a basic homepage; in normal mode, serve the usual UI routes