mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
Merge pull request #1206 from m3ayush/feat/radio-country-coverage
feat(radio): add configurable priority-country coverage
This commit is contained in:
7 files changed
+380
-20
No files matched your search
@@ -295,3 +295,8 @@ OVERPASS_UPSTREAMS=
|
|||||||
# frame-ancestors sources such as "https://example.com", or * for any page.
|
# frame-ancestors sources such as "https://example.com", or * for any page.
|
||||||
# Unset, no page may frame it. Other pages of the app can never be framed.
|
# Unset, no page may frame it. Other pages of the app can never be framed.
|
||||||
# GEV_EMBED_FRAME_ANCESTORS=
|
# GEV_EMBED_FRAME_ANCESTORS=
|
||||||
|
|
||||||
|
# Optional keyless Radio Browser coverage: up to 8 ISO alpha-2 countries.
|
||||||
|
# Each reserves up to 40 stations within the existing 750-station directory.
|
||||||
|
# Restart after changing. Leave blank for the existing global selection.
|
||||||
|
# RADIO_PRIORITY_COUNTRIES=IN,PL
|
||||||
+3
-1
@@ -183,7 +183,9 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei
|
|||||||
- **Autostrada del Brennero (A22) webcams.** Keyless. The camera list is one request to the Open Data Hub tourism API (`tourism.api.opendatahub.com/v1/WebcamInfo?source=a22`), run by NOI Techpark in South Tyrol, which republishes Autobrennero's own list of 13 motorway webcams with coordinates and kilometre markers. Frames are the operator's stills on `www.autobrennero.it/WebCamImg/km<N>.jpg`, refreshed about once a minute, and only the exact image for each camera's kilometre is registered. The feed names no bearing, so headings use the id-hash fallback at low confidence. The road climbs from about 20 m in the Po valley to about 1,370 m at the Brenner Pass, so each camera's ground elevation comes from a per-kilometre table sampled from the Copernicus GLO-90 DEM (via Open-Meteo's elevation API); a camera not in the table uses a 200 m prior. The Open Data Hub tags every record CC0 (`ClosedData: false`, Autobrennero as licence holder), but that tag is the aggregator's metadata and Autobrennero publishes no terms of its own for the images, so they are credited to the operator as a courtesy and are not redistributed. Frames are fetched at request time and never stored. Disable with `CCTV_A22_ENABLED=0`.
|
- **Autostrada del Brennero (A22) webcams.** Keyless. The camera list is one request to the Open Data Hub tourism API (`tourism.api.opendatahub.com/v1/WebcamInfo?source=a22`), run by NOI Techpark in South Tyrol, which republishes Autobrennero's own list of 13 motorway webcams with coordinates and kilometre markers. Frames are the operator's stills on `www.autobrennero.it/WebCamImg/km<N>.jpg`, refreshed about once a minute, and only the exact image for each camera's kilometre is registered. The feed names no bearing, so headings use the id-hash fallback at low confidence. The road climbs from about 20 m in the Po valley to about 1,370 m at the Brenner Pass, so each camera's ground elevation comes from a per-kilometre table sampled from the Copernicus GLO-90 DEM (via Open-Meteo's elevation API); a camera not in the table uses a 200 m prior. The Open Data Hub tags every record CC0 (`ClosedData: false`, Autobrennero as licence holder), but that tag is the aggregator's metadata and Autobrennero publishes no terms of its own for the images, so they are credited to the operator as a courtesy and are not redistributed. Frames are fetched at request time and never stored. Disable with `CCTV_A22_ENABLED=0`.
|
||||||
- **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals.
|
- **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals.
|
||||||
- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All sixteen registered regions are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Hamilton, Guelph, Burlington and YRT publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. A label is never invented: YRT runs a route `9101` that appears nowhere in its published routes, so it stays as the feed sends it. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. Ottawa’s OC Transpo falls to the same keyless admission rule as GO Transit — its realtime feed requires an API key. London Transit and Thunder Bay Transit publish vehicle positions over plain HTTP with no HTTPS endpoint available. Every other Ontario system — Brampton, Oakville, Niagara, Milton, Windsor, Greater Sudbury, UP Express and a dozen smaller operators — publishes static GTFS schedules only, with no realtime vehicle positions to register. Between the nine included and these exclusions, every Ontario realtime vehicle-position feed catalogued in the Mobility Database is accounted for.
|
- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All sixteen registered regions are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Hamilton, Guelph, Burlington and YRT publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. A label is never invented: YRT runs a route `9101` that appears nowhere in its published routes, so it stays as the feed sends it. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. Ottawa’s OC Transpo falls to the same keyless admission rule as GO Transit — its realtime feed requires an API key. London Transit and Thunder Bay Transit publish vehicle positions over plain HTTP with no HTTPS endpoint available. Every other Ontario system — Brampton, Oakville, Niagara, Milton, Windsor, Greater Sudbury, UP Express and a dozen smaller operators — publishes static GTFS schedules only, with no realtime vehicle positions to register. Between the nine included and these exclusions, every Ontario realtime vehicle-position feed catalogued in the Mobility Database is accounted for.
|
||||||
- **Radio Browser.** `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; schema-valid responses whose rows all fail the product's health policy do not count as successful queries. A usable partial cold catalog is explicitly `DEGRADED`, and non-array or empty successful payloads are rejected atomically. Individual structurally malformed rows are skipped rather than failing the whole query; the response carries their bounded `rejectedStationCount` (at most 10,000), which the client adds to its own rejected rows and reports as degraded coverage without discarding the accepted generation. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply.
|
- **Radio country coverage (optional).** Set `RADIO_PRIORITY_COUNTRIES=IN,PL` in the local `.env` and restart to include stations beyond the global click charts. The operator may choose up to eight unique ISO alpha-2 country codes; no key is needed. Each country adds one bounded query (at most 200 rows) and reserves up to 40 unique, usable stations inside the existing 750-station catalog. Country seeds precede specialist-tag seeds and global popularity fill; unused slots return to the shared pool. This is a coverage preference, not an exhaustive national directory or a guarantee of stations in every city. Countries with no eligible HTTPS MP3/AAC geolocated stations remain empty. An unset list preserves global selection. Country requests share the directory cache and three-worker pool; failed country queries are reported in coverage without blocking a healthy global refresh. Failed/degraded refreshes back off for one minute, with at most three mirrors per query.
|
||||||
|
|
||||||
|
- **Radio Browser.** In every installation, including when `RADIO_PRIORITY_COUNTRIES` is unset, each request tries at most three mirror candidates (later fallback candidates are skipped), and failed or partial catalog refreshes back off for 60 seconds. A cold-start failure therefore continues returning 503 during that delay even if upstream recovers. `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; broad/specialist responses whose rows all fail the product's health policy do not count as successful queries. Optional priority-country outcomes are advisory: valid, in-limit responses with no eligible stations succeed as empty results, while failed or malformed country queries report unsuccessful coverage without degrading the global catalog. A usable partial cold catalog is explicitly `DEGRADED`, and non-array or empty broad/specialist payloads are rejected atomically. Individual structurally malformed rows are skipped rather than failing the whole query; the response carries their bounded `rejectedStationCount` (at most 10,000), which the client adds to its own rejected rows and reports as degraded coverage without discarding the accepted generation. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply.
|
||||||
- **TomTom Traffic.** Optional and BYOK: without `TOMTOM_API_KEY` the traffic layer runs its built-in simulation and no TomTom data (or attribution) appears. With a key, flow vector tiles are fetched through the server-side `/api/tomtom` proxy (120 s cache + a daily tile-budget governor — `TOMTOM_DAILY_TILE_BUDGET`, default 6,000 — sized so a 31-day month stays inside TomTom's 200K monthly free allowance; still a configurable application safety ceiling, not a guarantee; TomTom's [current pricing](https://docs.tomtom.com/pricing/) lists 200K free tile requests per month) and the "Traffic flow data © TomTom" credit is registered in the Data attribution popover the moment live mode activates. TomTom data is served live and cached only transiently (≤120 s TTL under `.gev-cache/`, gitignored) — it is not bundled or redistributed. One 23 KB point-in-time tile snapshot is committed as a decode-test fixture (`src/data/fixtures/`, © TomTom, never served to the app).
|
- **TomTom Traffic.** Optional and BYOK: without `TOMTOM_API_KEY` the traffic layer runs its built-in simulation and no TomTom data (or attribution) appears. With a key, flow vector tiles are fetched through the server-side `/api/tomtom` proxy (120 s cache + a daily tile-budget governor — `TOMTOM_DAILY_TILE_BUDGET`, default 6,000 — sized so a 31-day month stays inside TomTom's 200K monthly free allowance; still a configurable application safety ceiling, not a guarantee; TomTom's [current pricing](https://docs.tomtom.com/pricing/) lists 200K free tile requests per month) and the "Traffic flow data © TomTom" credit is registered in the Data attribution popover the moment live mode activates. TomTom data is served live and cached only transiently (≤120 s TTL under `.gev-cache/`, gitignored) — it is not bundled or redistributed. One 23 KB point-in-time tile snapshot is committed as a decode-test fixture (`src/data/fixtures/`, © TomTom, never served to the app).
|
||||||
- **Routing (OSRM / FOSSGIS).** `/api/route` proxies the public OSRM instances FOSSGIS e.V. runs for the OpenStreetMap community (car, bike, foot profiles). They are keyless and intended for fair, interactive use — the proxy rate-limits clients (60/min, 200/min total), caps route span and response size, caches each route for 10 minutes, and identifies itself in the User-Agent. Heavy or automated use must run its own OSRM. Routes are computed from OpenStreetMap data (ODbL); the Directions layer and voice routes never redistribute them. A route the router cannot find is reported as such; the Directions layer draws nothing in that case, and voice routes fall back to a clearly labeled straight line.
|
- **Routing (OSRM / FOSSGIS).** `/api/route` proxies the public OSRM instances FOSSGIS e.V. runs for the OpenStreetMap community (car, bike, foot profiles). They are keyless and intended for fair, interactive use — the proxy rate-limits clients (60/min, 200/min total), caps route span and response size, caches each route for 10 minutes, and identifies itself in the User-Agent. Heavy or automated use must run its own OSRM. Routes are computed from OpenStreetMap data (ODbL); the Directions layer and voice routes never redistribute them. A route the router cannot find is reported as such; the Directions layer draws nothing in that case, and voice routes fall back to a clearly labeled straight line.
|
||||||
- **Re:Earth Terrain.** Keyless (no API key). Used two ways: (1) `src/mapStackController.js` swaps in a `Cesium.CesiumTerrainProvider` pointed at Re:Earth's `cesium-mesh/ellipsoid` quantized-mesh endpoint for globe stacks without a Cesium ion token (e.g. OSM), replacing a flat `EllipsoidTerrainProvider`; falls back to the flat provider if the endpoint can't be reached. (2) The server-side `/api/terrain/heights` proxy (disk-cached, serve-stale) resolves per-point ellipsoidal ground height for entity placement. Both are best-effort with a keyless-safe fallback (bundled EGM96 geoid math) if Re:Earth is unreachable.
|
- **Re:Earth Terrain.** Keyless (no API key). Used two ways: (1) `src/mapStackController.js` swaps in a `Cesium.CesiumTerrainProvider` pointed at Re:Earth's `cesium-mesh/ellipsoid` quantized-mesh endpoint for globe stacks without a Cesium ion token (e.g. OSM), replacing a flat `EllipsoidTerrainProvider`; falls back to the flat provider if the endpoint can't be reached. (2) The server-side `/api/terrain/heights` proxy (disk-cached, serve-stale) resolves per-point ellipsoidal ground height for entity placement. Both are best-effort with a keyless-safe fallback (bundled EGM96 geoid math) if Re:Earth is unreachable.
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
- Add optional keyless Radio priority-country coverage with up to 40 stations
|
||||||
|
per configured country inside the existing 750-station cap; the UK alias uses
|
||||||
|
the canonical GB code. Country query
|
||||||
|
failures do not block a healthy global catalog. Bound mirror attempts to three
|
||||||
|
and retry failed or partial refreshes after 60 seconds on all installations,
|
||||||
|
including those without priority countries configured (m3ayush, #1206).
|
||||||
+43
-2
@@ -4716,8 +4716,9 @@ programmatic activation do not trigger this reveal.
|
|||||||
|
|
||||||
Radio directory admission is atomic on both sides of the proxy boundary. A
|
Radio directory admission is atomic on both sides of the proxy boundary. A
|
||||||
refresh is healthy only when it reaches the minimum accepted-query and station
|
refresh is healthy only when it reaches the minimum accepted-query and station
|
||||||
coverage; schema-valid responses with zero normalized stations count as failed
|
coverage from broad/specialist queries; their schema-valid responses with zero
|
||||||
queries rather than inflating refresh health. Each specialist query also needs
|
normalized stations count as failed queries rather than inflating refresh health.
|
||||||
|
Optional priority-country outcomes do not gate catalog health. Each specialist query also needs
|
||||||
an accepted station whose normalized tags match that requested category; rows
|
an accepted station whose normalized tags match that requested category; rows
|
||||||
tagged only for another category remain usable catalog data but do not earn
|
tagged only for another category remain usable catalog data but do not earn
|
||||||
specialist health credit. A partial cold result remains
|
specialist health credit. A partial cold result remains
|
||||||
@@ -6318,6 +6319,46 @@ Existing catalog validation, category filters, tuning and voice playback behavio
|
|||||||
remain unchanged. Audio connects directly to the broadcaster after an explicit
|
remain unchanged. Audio connects directly to the broadcaster after an explicit
|
||||||
play action; the source does not relay or record streams.
|
play action; the source does not relay or record streams.
|
||||||
|
|
||||||
|
### Radio priority-country coverage
|
||||||
|
|
||||||
|
Optional `RADIO_PRIORITY_COUNTRIES` is a server-owned comma-separated list of
|
||||||
|
up to eight ISO alpha-2 codes (for example `IN,PL`). Restart after changing it.
|
||||||
|
The `UK` alias is canonicalized to `GB` before deduplication and querying.
|
||||||
|
It needs no API key and adds no POWER UP entry. An empty list preserves the
|
||||||
|
existing global/tag-based directory. Invalid configuration fails at startup.
|
||||||
|
|
||||||
|
Each country adds one Radio Browser search capped at 200 rows, with existing
|
||||||
|
HTTPS/geolocation/codec validation and an additional matching-country check.
|
||||||
|
Up to 40 unique accepted stations per country are seeded before the specialist
|
||||||
|
tag queries and global popularity fill, within the unchanged 750-station cap.
|
||||||
|
No country gets exhaustive coverage. A valid, in-limit country response with
|
||||||
|
zero eligible stations succeeds with zero selected stations.
|
||||||
|
The response's `coverage.priorityCountries` reports accepted query status and
|
||||||
|
selected counts when configured. The existing broad/specialist health policy
|
||||||
|
still applies separately. Country outcomes are advisory: failed, malformed or
|
||||||
|
oversized country queries report unsuccessful coverage but cannot degrade or
|
||||||
|
block admission of an otherwise healthy global catalog. Queries share the existing
|
||||||
|
three-worker pool, single-flight refresh and 45-minute cache.
|
||||||
|
Structurally malformed rows are skipped and counted in the upstream
|
||||||
|
`rejectedStationCount` diagnostic; mixed country responses retain their valid
|
||||||
|
rows, while an entirely malformed nonempty country response reports unsuccessful
|
||||||
|
coverage. The diagnostic does not block catalog admission.
|
||||||
|
|
||||||
|
For every installation, including those with no priority countries configured,
|
||||||
|
at most three mirrors are tried per request; fallback mirrors beyond the first
|
||||||
|
three candidates are not attempted. Failed or partial catalog refreshes retry
|
||||||
|
after one minute, so a cold-start failure can continue returning 503 for that
|
||||||
|
minute even if upstream recovers sooner. Healthy catalogs retain the 45-minute
|
||||||
|
cache. The seven-day last-good expiry and known-station-only click reporting
|
||||||
|
remain in force.
|
||||||
|
|
||||||
|
Validation: `node --test src/data/radioProxy.test.mjs` covers configuration,
|
||||||
|
country quotas under global popularity pressure, duplicate records, concurrency,
|
||||||
|
cache reuse, country mismatch/oversize/empty/ineligible responses, failure isolation on cold
|
||||||
|
and warm refreshes beyond seven days, and retry/backoff recovery both with and
|
||||||
|
without configured countries. `node scripts/qa-radio.mjs --url http://localhost:4173` covers the existing
|
||||||
|
750-station browser presentation and playback contract.
|
||||||
|
|
||||||
## Local RTL-SDR and Local ADS-B
|
## Local RTL-SDR and Local ADS-B
|
||||||
|
|
||||||
The Radio panel holds a Local RTL-SDR card below internet radio. One browser
|
The Radio panel holds a Local RTL-SDR card below internet radio. One browser
|
||||||
|
|||||||
@@ -7,9 +7,13 @@ export {
|
|||||||
publicRadioHttpsUrl,
|
publicRadioHttpsUrl,
|
||||||
} from './radio/stations.js';
|
} from './radio/stations.js';
|
||||||
export function radioBrowserProxy() {
|
export function radioBrowserProxy() {
|
||||||
const middleware = createRadioProxyMiddleware();
|
let middleware;
|
||||||
|
const initialize = () =>
|
||||||
|
(middleware ||= createRadioProxyMiddleware({
|
||||||
|
priorityCountries: process.env.RADIO_PRIORITY_COUNTRIES || '',
|
||||||
|
}));
|
||||||
const install = (server) => {
|
const install = (server) => {
|
||||||
server.middlewares.use('/api/radio', middleware);
|
server.middlewares.use('/api/radio', initialize());
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
name: 'radio-browser-proxy',
|
name: 'radio-browser-proxy',
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { normalizeRadioCountryInput } from '../../../src/data/radioCountry.js';
|
||||||
import { lookup as lookupDns } from 'node:dns/promises';
|
import { lookup as lookupDns } from 'node:dns/promises';
|
||||||
import { randomUUID } from 'node:crypto';
|
import { randomUUID } from 'node:crypto';
|
||||||
|
|
||||||
@@ -27,6 +28,34 @@ import {
|
|||||||
RADIO_FALLBACK_MIRRORS,
|
RADIO_FALLBACK_MIRRORS,
|
||||||
RADIO_REJECTED_STATION_COUNT_MAX,
|
RADIO_REJECTED_STATION_COUNT_MAX,
|
||||||
} from './constants.js';
|
} from './constants.js';
|
||||||
|
const PRIORITY_COUNTRY_LIMIT = 8;
|
||||||
|
const COUNTRY_QUERY_LIMIT = 200;
|
||||||
|
const COUNTRY_RESERVED_STATIONS = 40;
|
||||||
|
const REFRESH_RETRY_MS = 60_000;
|
||||||
|
const MAX_MIRROR_ATTEMPTS = 3;
|
||||||
|
|
||||||
|
/** Validate an operator-owned list; malformed configuration must not silently widen queries. */
|
||||||
|
export function parseRadioPriorityCountries(value = '') {
|
||||||
|
const entries = Array.isArray(value) ? value : String(value).split(',');
|
||||||
|
const countries = [];
|
||||||
|
for (const entry of entries) {
|
||||||
|
const input = String(entry).trim().toUpperCase();
|
||||||
|
if (!input) continue;
|
||||||
|
const normalized = normalizeRadioCountryInput(input);
|
||||||
|
if (!/^[A-Z]{2}$/.test(input) || !normalized.valid)
|
||||||
|
throw new TypeError(
|
||||||
|
'RADIO_PRIORITY_COUNTRIES requires ISO alpha-2 country codes',
|
||||||
|
);
|
||||||
|
const code = normalized.code;
|
||||||
|
if (!countries.includes(code)) countries.push(code);
|
||||||
|
}
|
||||||
|
if (countries.length > PRIORITY_COUNTRY_LIMIT)
|
||||||
|
throw new RangeError(
|
||||||
|
'RADIO_PRIORITY_COUNTRIES supports at most eight countries',
|
||||||
|
);
|
||||||
|
return countries;
|
||||||
|
}
|
||||||
|
|
||||||
async function mapRadioConcurrent(values, concurrency, mapper) {
|
async function mapRadioConcurrent(values, concurrency, mapper) {
|
||||||
const results = new Array(values.length);
|
const results = new Array(values.length);
|
||||||
let cursor = 0;
|
let cursor = 0;
|
||||||
@@ -49,7 +78,9 @@ export function createRadioProxyMiddleware({
|
|||||||
fetchImpl = null,
|
fetchImpl = null,
|
||||||
lookupImpl = lookupDns,
|
lookupImpl = lookupDns,
|
||||||
now = Date.now,
|
now = Date.now,
|
||||||
|
priorityCountries = [],
|
||||||
} = {}) {
|
} = {}) {
|
||||||
|
const countries = parseRadioPriorityCountries(priorityCountries);
|
||||||
let mirrorCache = { origins: [...RADIO_FALLBACK_MIRRORS], cachedAt: 0 };
|
let mirrorCache = { origins: [...RADIO_FALLBACK_MIRRORS], cachedAt: 0 };
|
||||||
let mirrorPromise = null;
|
let mirrorPromise = null;
|
||||||
let catalogCache = null;
|
let catalogCache = null;
|
||||||
@@ -61,6 +92,9 @@ export function createRadioProxyMiddleware({
|
|||||||
const catalogInstance = randomUUID();
|
const catalogInstance = randomUUID();
|
||||||
let servedStationIds = new Set();
|
let servedStationIds = new Set();
|
||||||
let refreshPromise = null;
|
let refreshPromise = null;
|
||||||
|
let retryAfter = 0;
|
||||||
|
let partialCatalog = null;
|
||||||
|
let refreshError = null;
|
||||||
|
|
||||||
async function fetchJson(url, maxBytes = RADIO_RESPONSE_MAX_BYTES) {
|
async function fetchJson(url, maxBytes = RADIO_RESPONSE_MAX_BYTES) {
|
||||||
const destination = radioProxyDestination(url);
|
const destination = radioProxyDestination(url);
|
||||||
@@ -139,7 +173,7 @@ export function createRadioProxyMiddleware({
|
|||||||
|
|
||||||
async function fetchPath(pathname) {
|
async function fetchPath(pathname) {
|
||||||
let lastError = null;
|
let lastError = null;
|
||||||
for (const origin of await mirrors()) {
|
for (const origin of (await mirrors()).slice(0, MAX_MIRROR_ATTEMPTS)) {
|
||||||
try {
|
try {
|
||||||
return await fetchJson(`${origin}${pathname}`);
|
return await fetchJson(`${origin}${pathname}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -160,20 +194,27 @@ export function createRadioProxyMiddleware({
|
|||||||
'aviation',
|
'aviation',
|
||||||
'marine',
|
'marine',
|
||||||
'traffic',
|
'traffic',
|
||||||
];
|
].map((tag) => ({ tag }));
|
||||||
|
const baseQueryCount = queries.length;
|
||||||
|
queries.push(...countries.map((country) => ({ country })));
|
||||||
const outcomes = await mapRadioConcurrent(
|
const outcomes = await mapRadioConcurrent(
|
||||||
queries,
|
queries,
|
||||||
3,
|
3,
|
||||||
async (tag, index) => {
|
async ({ tag, country }, index) => {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
has_geo_info: 'true',
|
has_geo_info: 'true',
|
||||||
is_https: 'true',
|
is_https: 'true',
|
||||||
hidebroken: 'true',
|
hidebroken: 'true',
|
||||||
order: 'clickcount',
|
order: 'clickcount',
|
||||||
reverse: 'true',
|
reverse: 'true',
|
||||||
limit: index === 0 ? '1800' : '220',
|
limit: country
|
||||||
|
? String(COUNTRY_QUERY_LIMIT)
|
||||||
|
: index === 0
|
||||||
|
? '1800'
|
||||||
|
: '220',
|
||||||
});
|
});
|
||||||
if (tag) params.set('tag', tag);
|
if (tag) params.set('tag', tag);
|
||||||
|
if (country) params.set('countrycode', country);
|
||||||
try {
|
try {
|
||||||
const rows = await fetchPath(`/json/stations/search?${params}`);
|
const rows = await fetchPath(`/json/stations/search?${params}`);
|
||||||
if (!Array.isArray(rows))
|
if (!Array.isArray(rows))
|
||||||
@@ -195,7 +236,12 @@ export function createRadioProxyMiddleware({
|
|||||||
const rejectedRows = rows.length - structuralRows.length;
|
const rejectedRows = rows.length - structuralRows.length;
|
||||||
const stations = structuralRows
|
const stations = structuralRows
|
||||||
.map(normalizeRadioBrowserStation)
|
.map(normalizeRadioBrowserStation)
|
||||||
.filter(Boolean);
|
.filter(
|
||||||
|
(station) =>
|
||||||
|
station && (!country || station.countryCode === country),
|
||||||
|
);
|
||||||
|
if (country && rows.length > COUNTRY_QUERY_LIMIT)
|
||||||
|
throw new Error('Radio Browser exceeded the country query limit');
|
||||||
const requestedTag = normalizeRadioTag(tag);
|
const requestedTag = normalizeRadioTag(tag);
|
||||||
const requestedTagCovered =
|
const requestedTagCovered =
|
||||||
!requestedTag ||
|
!requestedTag ||
|
||||||
@@ -207,10 +253,12 @@ export function createRadioProxyMiddleware({
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
// Query coverage is based on accepted rows, not merely a payload that
|
// A valid country response can contain no playable stations. Country
|
||||||
// happens to match the upstream schema. Specialist responses must
|
// coverage is advisory; only broad/specialist queries gate health.
|
||||||
// also contain an accepted station tagged for the requested category.
|
// Specialist responses need an accepted station with matching tags.
|
||||||
succeeded: stations.length > 0 && requestedTagCovered,
|
succeeded: country
|
||||||
|
? rows.length === 0 || structuralRows.length > 0
|
||||||
|
: stations.length > 0 && requestedTagCovered,
|
||||||
stations,
|
stations,
|
||||||
rejectedRows,
|
rejectedRows,
|
||||||
};
|
};
|
||||||
@@ -233,9 +281,24 @@ export function createRadioProxyMiddleware({
|
|||||||
seen.add(station.id);
|
seen.add(station.id);
|
||||||
selected.push(station);
|
selected.push(station);
|
||||||
};
|
};
|
||||||
|
// Reserve country slots first; low-click regional stations cannot lose all
|
||||||
|
// representation to the global charts. Keep room for all eight specialist
|
||||||
|
// seeds (8 * 45) and global fill even at the eight-country limit (8 * 40).
|
||||||
|
for (const rows of resultSets.slice(baseQueryCount)) {
|
||||||
|
const ranked = [...rows].sort(
|
||||||
|
(a, b) => b.clickCount - a.clickCount || a.id.localeCompare(b.id),
|
||||||
|
);
|
||||||
|
let added = 0;
|
||||||
|
for (const station of ranked) {
|
||||||
|
if (seen.has(station.id)) continue;
|
||||||
|
take(station);
|
||||||
|
if (++added >= COUNTRY_RESERVED_STATIONS) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Seed specialist station-tag queries before popularity fill so operational
|
// Seed specialist station-tag queries before popularity fill so operational
|
||||||
// categories remain represented even when global click charts skew musical.
|
// categories remain represented even when global click charts skew musical.
|
||||||
for (const rows of resultSets.slice(1)) rows.slice(0, 45).forEach(take);
|
for (const rows of resultSets.slice(1, baseQueryCount))
|
||||||
|
rows.slice(0, 45).forEach(take);
|
||||||
resultSets
|
resultSets
|
||||||
.flat()
|
.flat()
|
||||||
.sort(
|
.sort(
|
||||||
@@ -243,9 +306,9 @@ export function createRadioProxyMiddleware({
|
|||||||
)
|
)
|
||||||
.forEach(take);
|
.forEach(take);
|
||||||
const timestamp = now();
|
const timestamp = now();
|
||||||
const successfulQueries = outcomes.filter(
|
const successfulQueries = outcomes
|
||||||
(outcome) => outcome.succeeded,
|
.slice(0, baseQueryCount)
|
||||||
).length;
|
.filter((outcome) => outcome.succeeded).length;
|
||||||
const broadQueryHealthy =
|
const broadQueryHealthy =
|
||||||
outcomes[0].succeeded && outcomes[0].stations.length > 0;
|
outcomes[0].succeeded && outcomes[0].stations.length > 0;
|
||||||
const healthReasons = [];
|
const healthReasons = [];
|
||||||
@@ -261,7 +324,18 @@ export function createRadioProxyMiddleware({
|
|||||||
);
|
);
|
||||||
const coverage = {
|
const coverage = {
|
||||||
successfulQueries,
|
successfulQueries,
|
||||||
totalQueries: queries.length,
|
totalQueries: baseQueryCount,
|
||||||
|
...(countries.length
|
||||||
|
? {
|
||||||
|
priorityCountries: countries.map((country, index) => ({
|
||||||
|
countryCode: country,
|
||||||
|
succeeded: outcomes[baseQueryCount + index].succeeded,
|
||||||
|
stationCount: selected.filter(
|
||||||
|
(station) => station.countryCode === country,
|
||||||
|
).length,
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
stationCount: selected.length,
|
stationCount: selected.length,
|
||||||
healthyStationMinimum: RADIO_CATALOG_HEALTHY_MIN_STATIONS,
|
healthyStationMinimum: RADIO_CATALOG_HEALTHY_MIN_STATIONS,
|
||||||
};
|
};
|
||||||
@@ -315,7 +389,24 @@ export function createRadioProxyMiddleware({
|
|||||||
return { ...catalogCache, stale: false };
|
return { ...catalogCache, stale: false };
|
||||||
}
|
}
|
||||||
if (!refreshPromise) {
|
if (!refreshPromise) {
|
||||||
refreshPromise = refreshCatalog().finally(() => {
|
refreshPromise = (async () => {
|
||||||
|
if (now() < retryAfter) {
|
||||||
|
if (refreshError) throw refreshError;
|
||||||
|
return partialCatalog;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const catalog = await refreshCatalog();
|
||||||
|
refreshError = null;
|
||||||
|
partialCatalog = catalog.degraded ? catalog : null;
|
||||||
|
retryAfter = catalog.degraded ? now() + REFRESH_RETRY_MS : 0;
|
||||||
|
return catalog;
|
||||||
|
} catch (error) {
|
||||||
|
refreshError = error;
|
||||||
|
partialCatalog = null;
|
||||||
|
retryAfter = now() + REFRESH_RETRY_MS;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
})().finally(() => {
|
||||||
refreshPromise = null;
|
refreshPromise = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -541,6 +541,191 @@ test('a mirror answering an invalid reason phrase rejects instead of crashing',
|
|||||||
await assert.rejects(Promise.race([fetchMirror(), crashed]), TypeError);
|
await assert.rejects(Promise.race([fetchMirror(), crashed]), TypeError);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('priority-country configuration is bounded, normalized and validated before requests', async () => {
|
||||||
|
const { parseRadioPriorityCountries } = await import('../../server/providers/radio/catalog.js');
|
||||||
|
assert.deepEqual(parseRadioPriorityCountries(' in, PL,in, '), ['IN', 'PL']);
|
||||||
|
assert.deepEqual(parseRadioPriorityCountries(''), []);
|
||||||
|
assert.deepEqual(parseRadioPriorityCountries('uk,GB,UK'), ['GB']);
|
||||||
|
assert.deepEqual(parseRadioPriorityCountries('US,CA,IN,PL,DE,FR,UK,GB,JP'), ['US', 'CA', 'IN', 'PL', 'DE', 'FR', 'GB', 'JP']);
|
||||||
|
for (const value of ['ZZ', 'India', 'IN&limit=9999', 'US,CA,IN,PL,DE,FR,GB,JP,AU']) {
|
||||||
|
assert.throws(() => createProxy({ priorityCountries: value }), /RADIO_PRIORITY_COUNTRIES/);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('UK aliases query and report GB once and retain British stations', async () => {
|
||||||
|
const countryQueries = [];
|
||||||
|
const middleware = createProxy({
|
||||||
|
priorityCountries: 'UK,GB',
|
||||||
|
fetchImpl: async (url) => {
|
||||||
|
const parsed = new URL(url);
|
||||||
|
if (parsed.pathname === '/json/servers')
|
||||||
|
return responseJson([{ name: 'de1.api.radio-browser.info' }]);
|
||||||
|
const country = parsed.searchParams.get('countrycode');
|
||||||
|
if (country) {
|
||||||
|
countryQueries.push(country);
|
||||||
|
return responseJson([station({ country: 'United Kingdom', countrycode: 'GB' })]);
|
||||||
|
}
|
||||||
|
return responseJson(healthyRowsForQuery(url));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const response = await invoke(middleware, '/stations');
|
||||||
|
assert.equal(response.status, 200);
|
||||||
|
const body = JSON.parse(response.body);
|
||||||
|
assert.deepEqual(countryQueries, ['GB']);
|
||||||
|
assert.deepEqual(body.coverage.priorityCountries, [
|
||||||
|
{ countryCode: 'GB', succeeded: true, stationCount: 1 },
|
||||||
|
]);
|
||||||
|
assert.equal(body.stations.find((row) => row.id === UUID)?.countryCode, 'GB');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('low-click country stations survive a full global catalog, with bounded cached queries and deduplication', async () => {
|
||||||
|
const calls = [];
|
||||||
|
let active = 0;
|
||||||
|
let peak = 0;
|
||||||
|
const middleware = createProxy({
|
||||||
|
priorityCountries: 'IN,PL',
|
||||||
|
fetchImpl: async (url) => {
|
||||||
|
const parsed = new URL(url);
|
||||||
|
calls.push(parsed);
|
||||||
|
if (parsed.pathname === '/json/servers') return responseJson([{ name: 'de1.api.radio-browser.info' }]);
|
||||||
|
if (parsed.pathname.startsWith('/json/url/')) return responseJson({ ok: true });
|
||||||
|
peak = Math.max(peak, ++active);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1));
|
||||||
|
active--;
|
||||||
|
const country = parsed.searchParams.get('countrycode');
|
||||||
|
if (country) {
|
||||||
|
assert.equal(parsed.searchParams.get('limit'), '200');
|
||||||
|
assert.equal(parsed.searchParams.get('is_https'), 'true');
|
||||||
|
const rows = catalogRows(country === 'IN' ? '10000000' : '20000000', 'community', 60)
|
||||||
|
.map((row) => ({ ...row, countrycode: country, clickcount: 0 }));
|
||||||
|
return responseJson([rows[0], ...rows]);
|
||||||
|
}
|
||||||
|
return responseJson(catalogRows('30000000', queryTag(url) || 'news', 900));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const responses = await Promise.all([invoke(middleware, '/stations'), invoke(middleware, '/stations')]);
|
||||||
|
const body = JSON.parse(responses[0].body);
|
||||||
|
assert.equal(body.degraded, false);
|
||||||
|
assert.equal(body.stations.length, 750);
|
||||||
|
assert.equal(new Set(body.stations.map((row) => row.id)).size, 750);
|
||||||
|
for (const country of ['IN', 'PL'])
|
||||||
|
assert.ok(body.stations.filter((row) => row.countryCode === country).length >= 40);
|
||||||
|
assert.ok(body.stations.some((row) => row.countryCode === 'US'));
|
||||||
|
assert.equal(calls.filter((url) => url.pathname.includes('/stations/')).length, 11);
|
||||||
|
assert.ok(peak <= 3);
|
||||||
|
const count = calls.length;
|
||||||
|
await invoke(middleware, '/stations');
|
||||||
|
assert.equal(calls.length, count, 'country queries share the 45-minute cache');
|
||||||
|
const id = body.stations.find((row) => row.countryCode === 'IN').id;
|
||||||
|
assert.equal((await invoke(middleware, `/click/${id}`, 'POST')).status, 204);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('country failures never block cold or warm global catalog admission, even after seven days', async () => {
|
||||||
|
for (const coldFailure of [false, true]) {
|
||||||
|
let clock = 4_000_000;
|
||||||
|
let fail = coldFailure;
|
||||||
|
let calls = 0;
|
||||||
|
const middleware = createProxy({
|
||||||
|
priorityCountries: ['IN'], now: () => clock,
|
||||||
|
fetchImpl: async (url) => {
|
||||||
|
calls++;
|
||||||
|
if (String(url).includes('/json/servers')) return responseJson([{ name: 'de1.api.radio-browser.info' }]);
|
||||||
|
if (new URL(url).searchParams.has('countrycode')) {
|
||||||
|
if (fail) throw new Error('offline');
|
||||||
|
return responseJson([station({ countrycode: 'IN', country: 'India', tags: 'community' })]);
|
||||||
|
}
|
||||||
|
return responseJson(healthyRowsForQuery(url));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
let generation = 0;
|
||||||
|
for (const elapsed of [0, 46 * 60 * 1000, 8 * 24 * 60 * 60 * 1000]) {
|
||||||
|
clock += elapsed;
|
||||||
|
if (elapsed) fail = true;
|
||||||
|
const response = await invoke(middleware, '/stations');
|
||||||
|
const body = JSON.parse(response.body);
|
||||||
|
assert.equal(response.status, 200);
|
||||||
|
assert.equal(body.stale, false);
|
||||||
|
assert.equal(body.degraded, false);
|
||||||
|
assert.ok(body.acceptedGeneration > generation);
|
||||||
|
generation = body.acceptedGeneration;
|
||||||
|
assert.equal(body.coverage.priorityCountries[0].succeeded, !fail);
|
||||||
|
assert.equal(body.coverage.priorityCountries[0].stationCount, fail ? 0 : 1);
|
||||||
|
const count = calls;
|
||||||
|
clock += 60_001;
|
||||||
|
assert.deepEqual(JSON.parse((await invoke(middleware, '/stations')).body), body);
|
||||||
|
assert.equal(calls, count, 'country failure does not shorten the healthy cache');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('valid countries with no eligible stations are accepted and cached; malformed country responses stay isolated', async () => {
|
||||||
|
for (const mode of ['wrong', 'oversized', 'empty', 'ineligible', 'malformed']) {
|
||||||
|
let clock = 4_000_000;
|
||||||
|
let calls = 0;
|
||||||
|
const middleware = createProxy({
|
||||||
|
priorityCountries: ['IN'], now: () => clock,
|
||||||
|
fetchImpl: async (url) => {
|
||||||
|
calls++;
|
||||||
|
if (String(url).includes('/json/servers')) return responseJson([{ name: 'de1.api.radio-browser.info' }]);
|
||||||
|
if (new URL(url).searchParams.has('countrycode')) {
|
||||||
|
const rows = {
|
||||||
|
empty: [], wrong: [station()], malformed: [{ name: 'missing fields' }],
|
||||||
|
oversized: catalogRows('10000000', 'community', 201).map((row) => ({ ...row, countrycode: 'IN' })),
|
||||||
|
ineligible: [{ hls: 1 }, { codec: 'OGG' }, { codec: 'OPUS' }, { url_resolved: 'https://127.0.0.1/live.mp3' }]
|
||||||
|
.map((overrides) => station({ countrycode: 'IN', ...overrides })),
|
||||||
|
};
|
||||||
|
return responseJson(rows[mode]);
|
||||||
|
}
|
||||||
|
return responseJson(healthyRowsForQuery(url));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const response = await invoke(middleware, '/stations');
|
||||||
|
const body = JSON.parse(response.body);
|
||||||
|
assert.equal(response.status, 200, mode);
|
||||||
|
assert.equal(body.degraded, false, mode);
|
||||||
|
assert.ok(body.acceptedGeneration > 0, mode);
|
||||||
|
assert.equal(body.coverage.priorityCountries[0].stationCount, 0, mode);
|
||||||
|
assert.equal(body.coverage.priorityCountries[0].succeeded, !['oversized', 'malformed'].includes(mode), mode);
|
||||||
|
const count = calls;
|
||||||
|
clock += 44 * 60 * 1000;
|
||||||
|
assert.deepEqual(JSON.parse((await invoke(middleware, '/stations')).body), body);
|
||||||
|
assert.equal(calls, count, `${mode} country response preserves the 45-minute cache`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const priorityCountries of ['', 'IN']) {
|
||||||
|
test(`cold failures coalesce, bound mirrors and back off with priority countries ${priorityCountries || 'unset'}`, async () => {
|
||||||
|
let clock = Date.UTC(2026, 0, 1);
|
||||||
|
let calls = 0;
|
||||||
|
let offline = true;
|
||||||
|
const middleware = createProxy({
|
||||||
|
priorityCountries, now: () => clock,
|
||||||
|
fetchImpl: async (url) => {
|
||||||
|
calls++;
|
||||||
|
if (String(url).includes('/json/servers')) return responseJson([{ name: 'de1.api.radio-browser.info' }]);
|
||||||
|
if (offline) throw new Error('offline');
|
||||||
|
if (new URL(url).searchParams.has('countrycode')) return responseJson([]);
|
||||||
|
return responseJson(healthyRowsForQuery(url));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const responses = await Promise.all([invoke(middleware, '/stations'), invoke(middleware, '/stations')]);
|
||||||
|
assert.ok(responses.every((response) => response.status === 503));
|
||||||
|
const initial = calls;
|
||||||
|
assert.equal(initial, 1 + (priorityCountries ? 10 : 9) * 3, 'one discovery and at most three mirrors per query');
|
||||||
|
offline = false;
|
||||||
|
clock += 59_999;
|
||||||
|
assert.equal((await invoke(middleware, '/stations')).status, 503);
|
||||||
|
assert.equal(calls, initial);
|
||||||
|
clock += 2;
|
||||||
|
const recovered = await invoke(middleware, '/stations');
|
||||||
|
assert.equal(recovered.status, 200);
|
||||||
|
assert.equal(JSON.parse(recovered.body).degraded, false);
|
||||||
|
assert.ok(calls > initial);
|
||||||
|
const afterRecovery = calls;
|
||||||
|
await invoke(middleware, '/stations');
|
||||||
|
assert.equal(calls, afterRecovery);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
test('case expansion is capped after tag normalization in the portable and server station path', () => {
|
test('case expansion is capped after tag normalization in the portable and server station path', () => {
|
||||||
const row = normalizeRadioBrowserStation(station({tags: 'İ'.repeat(80) + ', NEWS__RADIO ,news-radio'}));
|
const row = normalizeRadioBrowserStation(station({tags: 'İ'.repeat(80) + ', NEWS__RADIO ,news-radio'}));
|
||||||
@@ -599,3 +784,29 @@ test('server structural rejections reach the client diagnostic without discardin
|
|||||||
radioLayer.destroy();
|
radioLayer.destroy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('country coverage retains valid rows and upstream rejection diagnostics in a cached healthy catalog', async () => {
|
||||||
|
let calls = 0;
|
||||||
|
const middleware = createProxy({
|
||||||
|
priorityCountries: 'IN',
|
||||||
|
fetchImpl: async (url) => {
|
||||||
|
calls++;
|
||||||
|
if (String(url).includes('/json/servers')) return responseJson([{ name: 'de1.api.radio-browser.info' }]);
|
||||||
|
if (new URL(url).searchParams.has('countrycode')) return responseJson([
|
||||||
|
station({ stationuuid: '60000000-0000-4000-8000-000000000001', countrycode: 'IN' }),
|
||||||
|
{ name: 'missing required fields' },
|
||||||
|
]);
|
||||||
|
return responseJson(healthyRowsForQuery(url));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const response = await invoke(middleware, '/stations');
|
||||||
|
const body = JSON.parse(response.body);
|
||||||
|
assert.equal(response.status, 200);
|
||||||
|
assert.equal(body.degraded, false);
|
||||||
|
assert.equal(body.rejectedStationCount, 1);
|
||||||
|
assert.deepEqual(body.coverage.priorityCountries, [{ countryCode: 'IN', succeeded: true, stationCount: 1 }]);
|
||||||
|
const count = calls;
|
||||||
|
assert.deepEqual(JSON.parse((await invoke(middleware, '/stations')).body), body);
|
||||||
|
assert.equal(calls, count);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user