From a3e13df2797a0563d58ba8ca6d2f37f861830b76 Mon Sep 17 00:00:00 2001 From: Daniel Santillan Date: Wed, 23 Sep 2026 20:45:21 -0400 Subject: [PATCH] La radio no se dibuja para un invitado ni contra un servidor viejo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Las emisoras las busca el servidor, así que dos situaciones que no son bugs se veían como uno: sin sesión (el modo invitado nunca habla con la api) y una api más vieja que la app —se despliegan por separado, y un deploy que reconstruyó `web` y no el contenedor de la api es una pantalla cuyos pedidos fallan todos. Ahora la sección lo dice y no pide nada en ninguno de los dos casos. Para poder distinguirlos, `radio` entra en `features` (`GET /api/config`), que es exactamente para lo que existe esa lista, y queda documentado en la especificación junto con `features` entero —que hasta ahora no estaba. De paso: la fila y la barra caen al marcador de posición cuando el logo o la portada no cargan, que es el caso de una parte del directorio. --- api/openapi.yaml | 26 ++++++++++++- api/server.js | 1 + docs/RADIO.md | 14 +++++++ frontend/src/locales/es.js | 2 + frontend/src/views/Music.jsx | 61 ++++++++++++++++++++----------- frontend/src/views/Music.test.jsx | 26 ++++++++++++- website/api.html | 3 +- 7 files changed, 108 insertions(+), 25 deletions(-) diff --git a/api/openapi.yaml b/api/openapi.yaml index f9f7d36..f28c65b 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -130,6 +130,12 @@ paths: description: | The flags the login screen needs before anyone is signed in. Both reflect environment variables on the server (`INVITE_ONLY`, `ALLOW_GUEST`). + + `features` is the one that exists because the app and the api are deployed separately: the + frontend is rebuilt from source on every deploy while the api's code lives inside its + container, so a deploy can leave a new screen on top of an older api. Naming what this + server can do lets a screen say "this server is older than the app" instead of showing a + request that quietly fails — or, worse, a number that never moves. security: [] responses: '200': @@ -147,7 +153,25 @@ paths: description: >- When false, the client hides "continue without account". Guest mode is purely client-side and never calls this API. - example: { invite_only: true, allow_guest: false } + features: + type: array + description: >- + What this build of the api supports, so a client can tell an older server from + a broken one. Clients must treat a missing or non-array `features` as "old + server", never as "supports everything". + items: + type: string + enum: [vitals, vitals.hours, vitals.receipt, music.lookup, radio, insights] + coach: + type: object + description: Present only when the AI Coach is configured on this instance. + properties: + enabled: { type: boolean } + provider: { type: string } + providerLabel: { type: string } + authMode: { type: string, enum: [instance, byok] } + community: { type: boolean } + example: { invite_only: true, allow_guest: false, features: [vitals, radio, insights] } /api/me: get: diff --git a/api/server.js b/api/server.js index b004538..05b2f23 100644 --- a/api/server.js +++ b/api/server.js @@ -35,6 +35,7 @@ export const API_FEATURES = Object.freeze([ 'vitals.hours', // hourly buckets, and GET /api/vitals/hours 'vitals.receipt', // per-metric `shape`, and per-day `own` / `hours_sum` 'music.lookup', // POST /api/music/lookup + 'radio', // GET /api/radio, GET /api/radio/now 'insights' // GET/POST /api/insights (the second opinion) ]); diff --git a/docs/RADIO.md b/docs/RADIO.md index 5a339ae..5d837d6 100644 --- a/docs/RADIO.md +++ b/docs/RADIO.md @@ -86,6 +86,20 @@ under a locked screen in a WebView needs `UIBackgroundModes: audio` (iOS) and a (Android) in the shell's own config. Neither is set today — that is described in [docs/MOBILE.md](docs/MOBILE.md), and it only affects the packaged builds, not the PWA. +## When the radio isn't there + +Two situations look like a bug and are not, so the screen says which one it is instead of showing a +request that failed: + +- **Nobody is signed in.** Guest mode is client-side only and never talks to the api, and the station + list is the server's job — so the section says the radio needs a profile. No request is made. +- **The api is older than the app.** They ship separately: `web` is rebuilt from source on every + deploy, while the api's code lives inside its container, so a deploy can leave a new screen on top + of an api that has never heard of `/api/radio`. `GET /api/config` lists what that api can do + (`features`, and this build answers `radio`), so "old server" is detectable — the section says so, + quietly, rather than offering chips that 404. The same list is what keeps the Salud screen from + blaming the data when it is really the container. + ## Saving a station The star on a row saves the station to your profile (`music.stations`), and saved ones are pinned diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js index c6a39d8..5642460 100644 --- a/frontend/src/locales/es.js +++ b/frontend/src/locales/es.js @@ -1427,6 +1427,8 @@ export default { 'Saved to your stations': 'Guardada en tus emisoras', 'Nothing playing. Pick a station below.': 'No hay nada sonando. Elegí una emisora abajo.', 'These are public radio streams: nothing is downloaded, and the audio goes straight from the station to your phone. The first four of each genre are stations with no advertising at all.': 'Son radios públicas: no se descarga nada y el audio va directo de la emisora a tu teléfono. Las primeras de cada género son emisoras sin publicidad.', + 'The radio comes from your server, so it needs a profile: sign in and the stations appear here.': 'La radio viene de tu servidor, así que necesita un perfil: entrá a tu cuenta y las emisoras aparecen acá.', + 'Your server has not been updated for the radio yet: it is the server that finds the stations, and this app is newer than it. Restarting it should be enough.': 'Tu servidor todavía no se actualizó para la radio: las emisoras las busca el servidor, y esta app es más nueva que él. Reiniciarlo debería alcanzar.', 'What arrived last': 'Qué llegó en el último envío', 'Datapoints in the last sync': 'Datos en el último envío', 'How they were stamped': 'Cómo vienen marcados', diff --git a/frontend/src/views/Music.jsx b/frontend/src/views/Music.jsx index 790185b..7da986e 100644 --- a/frontend/src/views/Music.jsx +++ b/frontend/src/views/Music.jsx @@ -102,8 +102,17 @@ function RadioSection() { const playRadio = useUI(s => s.playRadio) const toast = useUI(s => s.toast) const S = useStore(s => s.S) + const user = useStore(s => s.user) + const cfg = useStore(s => s.config) const addStation = useStore(s => s.addStation) const removeStation = useStore(s => s.removeStation) + /* The list comes from the server, so two situations have to be told apart from a bug rather than + shown as one: nobody is signed in (guest mode never talks to the api at all), and the api is + older than the app — they ship separately, so a deploy that refreshed `web` and not the api + container leaves a screen whose every request is a 401/404. Both are quiet lines instead of a + toast, and no request is made in either case. */ + const staleApi = !!cfg && Array.isArray(cfg.features) && !cfg.features.includes('radio') + const canRadio = !!user && !staleApi const [genres, setGenres] = useState(null) const [genre, setGenre] = useState(null) const [stations, setStations] = useState(null) @@ -125,7 +134,7 @@ function RadioSection() { .catch(e => toast(e.message)) .finally(() => setBusy(false)) } - useEffect(() => { load(null) }, []) + useEffect(() => { if (canRadio) load(null) }, [canRadio]) const play = station => { // Synchronous on purpose: `play()` has to happen inside this tap for iOS to allow it. @@ -154,27 +163,35 @@ function RadioSection() { return <>

{t('Radio')}{stations ? · {t('{0} stations', stations.length)} : null}

-
- {t('These are public radio streams: nothing is downloaded, and the audio goes straight from the station to your phone. The first four of each genre are stations with no advertising at all.')} -
-
- {(genres || []).map(g => )} -
- {saved.length > 0 && <> -
{t('Saved stations')}
- {saved.map(st => row(st))} - } - {busy && !stations &&
{t('Loading stations…')}
} - {stations && stations.map(st => row(st))} - {stations && !stations.length &&
- {t('That station is not answering. Try another one.')} -
} - {radio &&
- {radio.playing ? t('Playing {0}', radio.station.name) : t('Paused: {0}', radio.station.name)} -
} - {!radio &&
{t('Nothing playing. Pick a station below.')}
} + {!canRadio + ?
+ {staleApi + ? t('Your server has not been updated for the radio yet: it is the server that finds the stations, and this app is newer than it. Restarting it should be enough.') + : t('The radio comes from your server, so it needs a profile: sign in and the stations appear here.')} +
+ : <> +
+ {t('These are public radio streams: nothing is downloaded, and the audio goes straight from the station to your phone. The first four of each genre are stations with no advertising at all.')} +
+
+ {(genres || []).map(g => )} +
+ {saved.length > 0 && <> +
{t('Saved stations')}
+ {saved.map(st => row(st))} + } + {busy && !stations &&
{t('Loading stations…')}
} + {stations && stations.map(st => row(st))} + {stations && !stations.length &&
+ {t('That station is not answering. Try another one.')} +
} + {radio &&
+ {radio.playing ? t('Playing {0}', radio.station.name) : t('Paused: {0}', radio.station.name)} +
} + {!radio &&
{t('Nothing playing. Pick a station below.')}
} + } } diff --git a/frontend/src/views/Music.test.jsx b/frontend/src/views/Music.test.jsx index 8efcaa5..abcabdc 100644 --- a/frontend/src/views/Music.test.jsx +++ b/frontend/src/views/Music.test.jsx @@ -44,7 +44,13 @@ beforeEach(() => { host = document.createElement('div') document.body.appendChild(host) root = createRoot(host) - useStore.setState(s => ({ S: { ...s.S, music: { user: '', playlists: [] } } })) + useStore.setState(s => ({ + S: { ...s.S, music: { user: '', playlists: [] } }, + // The radio section is server-backed: it draws nothing for a guest or against an api older + // than the app. Every test here starts signed in, on a server that answers. + user: { id: 'u1', name: 'Test' }, + config: null + })) }) afterEach(() => { act(() => root.unmount()); host.remove() }) @@ -159,6 +165,24 @@ describe('Música', () => { expect(host.textContent).not.toContain('Saved stations') }) + /* Two situations that are not bugs, and used to look like one: nothing signed in (guest mode + never talks to the api), and an api older than the app — they ship separately, so a deploy that + refreshed the frontend and not the api container is a screen whose every request fails. Both + are a quiet line, and neither makes a request. */ + it('tells a guest where the radio comes from, without asking the server', async () => { + useStore.setState({ user: null }) + await mount() + expect(host.textContent).toContain('The radio comes from your server, so it needs a profile') + expect(api).not.toHaveBeenCalled() + }) + + it('says the server is older when it does not offer the radio yet', async () => { + useStore.setState({ config: { features: ['vitals', 'insights'] } }) + await mount() + expect(host.textContent).toContain('Your server has not been updated for the radio yet') + expect(api).not.toHaveBeenCalled() + }) + it('saving the same link twice does not duplicate the card', async () => { useStore.setState(s => ({ S: { ...s.S, music: { user: '', playlists: [] } } })) act(() => { useStore.getState().addPlaylist(item()) }) diff --git a/website/api.html b/website/api.html index 2433d5f..ded6acd 100644 --- a/website/api.html +++ b/website/api.html @@ -309,6 +309,7 @@ main.api-main .lead { color: var(--fg-2); max-width: 58ch; margin: 14px 0 0; fon

The flags the login screen needs before anyone is signed in. Both reflect environment variables on the server (INVITE_ONLY, ALLOW_GUEST).

+

features is the one that exists because the app and the api are deployed separately: the frontend is rebuilt from source on every deploy while the api's code lives inside its container, so a deploy can leave a new screen on top of an older api. Naming what this server can do lets a screen say "this server is older than the app" instead of showing a request that quietly fails — or, worse, a number that never moves.

Public — no authentication required.

@@ -316,7 +317,7 @@ main.api-main .lead { color: var(--fg-2); max-width: 58ch; margin: 14px 0 0; fon
200 - Instance flags.{ invite_only: boolean, allow_guest: boolean } + Instance flags.{ invite_only: boolean, allow_guest: boolean, features: ("vitals" | "vitals.hours" | "vitals.receipt" | "music.lookup" | "radio" | "insights")[], coach: object }