La radio no se dibuja para un invitado ni contra un servidor viejo
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
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.
This commit is contained in:
1 parent
8f26b536fd
commit
a3e13df279
7 files changed
+108
-25
No files matched your search
+25
-1
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
]);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 <>
|
||||
<h4 className="sec">{t('Radio')}{stations ? <span className="vh-window"> · {t('{0} stations', stations.length)}</span> : null}</h4>
|
||||
<div className="small dim" style={{ margin: '0 2px 8px', lineHeight: 1.45 }}>
|
||||
{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.')}
|
||||
</div>
|
||||
<div className="chips" style={{ marginBottom: 10 }}>
|
||||
{(genres || []).map(g => <button key={g.key}
|
||||
className={'chip' + (genre === g.key ? ' on' : '')}
|
||||
onClick={() => load(g.key)}>{g.label}</button>)}
|
||||
</div>
|
||||
{saved.length > 0 && <>
|
||||
<div className="mus-sub-h">{t('Saved stations')}</div>
|
||||
{saved.map(st => row(st))}
|
||||
</>}
|
||||
{busy && !stations && <div className="small dim" style={{ margin: '0 2px 10px' }}>{t('Loading stations…')}</div>}
|
||||
{stations && stations.map(st => row(st))}
|
||||
{stations && !stations.length && <div className="small dim" style={{ margin: '0 2px 10px' }}>
|
||||
{t('That station is not answering. Try another one.')}
|
||||
</div>}
|
||||
{radio && <div className="small dim" style={{ margin: '8px 2px 0' }}>
|
||||
{radio.playing ? t('Playing {0}', radio.station.name) : t('Paused: {0}', radio.station.name)}
|
||||
</div>}
|
||||
{!radio && <div className="small dim" style={{ margin: '8px 2px 0' }}>{t('Nothing playing. Pick a station below.')}</div>}
|
||||
{!canRadio
|
||||
? <div className="small dim" style={{ margin: '0 2px 8px', lineHeight: 1.45 }}>
|
||||
{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.')}
|
||||
</div>
|
||||
: <>
|
||||
<div className="small dim" style={{ margin: '0 2px 8px', lineHeight: 1.45 }}>
|
||||
{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.')}
|
||||
</div>
|
||||
<div className="chips" style={{ marginBottom: 10 }}>
|
||||
{(genres || []).map(g => <button key={g.key}
|
||||
className={'chip' + (genre === g.key ? ' on' : '')}
|
||||
onClick={() => load(g.key)}>{g.label}</button>)}
|
||||
</div>
|
||||
{saved.length > 0 && <>
|
||||
<div className="mus-sub-h">{t('Saved stations')}</div>
|
||||
{saved.map(st => row(st))}
|
||||
</>}
|
||||
{busy && !stations && <div className="small dim" style={{ margin: '0 2px 10px' }}>{t('Loading stations…')}</div>}
|
||||
{stations && stations.map(st => row(st))}
|
||||
{stations && !stations.length && <div className="small dim" style={{ margin: '0 2px 10px' }}>
|
||||
{t('That station is not answering. Try another one.')}
|
||||
</div>}
|
||||
{radio && <div className="small dim" style={{ margin: '8px 2px 0' }}>
|
||||
{radio.playing ? t('Playing {0}', radio.station.name) : t('Paused: {0}', radio.station.name)}
|
||||
</div>}
|
||||
{!radio && <div className="small dim" style={{ margin: '8px 2px 0' }}>{t('Nothing playing. Pick a station below.')}</div>}
|
||||
</>}
|
||||
</>
|
||||
}
|
||||
|
||||
|
||||
@@ -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()) })
|
||||
|
||||
+2
-1
@@ -309,6 +309,7 @@ main.api-main .lead { color: var(--fg-2); max-width: 58ch; margin: 14px 0 0; fon
|
||||
</summary>
|
||||
<div class="ep-body">
|
||||
<p>The flags the login screen needs before anyone is signed in. Both reflect environment variables on the server (<code>INVITE_ONLY</code>, <code>ALLOW_GUEST</code>).</p>
|
||||
<p><code>features</code> 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.</p>
|
||||
<p class="ep-auth"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2.5"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg><span>Public — no authentication required.</span></p>
|
||||
|
||||
|
||||
@@ -316,7 +317,7 @@ main.api-main .lead { color: var(--fg-2); max-width: 58ch; margin: 14px 0 0; fon
|
||||
<div class="ptab">
|
||||
<div class="prow rrow">
|
||||
<span class="r-code s2">200</span>
|
||||
<span class="p-desc">Instance flags.<span class="r-sig">{ invite_only: boolean, allow_guest: boolean }</span></span>
|
||||
<span class="p-desc">Instance flags.<span class="r-sig">{ invite_only: boolean, allow_guest: boolean, features: ("vitals" | "vitals.hours" | "vitals.receipt" | "music.lookup" | "radio" | "insights")[], coach: object }</span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user