diff --git a/server/lib/services.ts b/server/lib/services.ts index 0918f2b..582a4cf 100644 --- a/server/lib/services.ts +++ b/server/lib/services.ts @@ -3842,7 +3842,7 @@ async function testService( label: string, optional: boolean, required: Array<[name: string, value: string]>, - check: () => Promise + check: () => Promise ): Promise { const missing = required.filter(([, value]) => !value.trim()).map(([name]) => name); if (missing.length === required.length) { @@ -3853,8 +3853,8 @@ async function testService( } try { - await check(); - return { key, label, ok: true, message: 'Connected', configured: true, optional }; + const note = await check(); + return { key, label, ok: true, message: note || 'Connected', configured: true, optional }; } catch (error) { const message = errorMessage(error); // Node reports network errors as a bare "fetch failed". @@ -3879,6 +3879,7 @@ function testSonarr(config: AppConfig): Promise { 'X-Api-Key': config.sonarr.apiKey } }); + return warnIfKeyNotChecked('Sonarr', `${config.sonarr.baseUrl}/api/v3/health`); }); } @@ -3889,14 +3890,26 @@ function testRadarr(config: AppConfig): Promise { 'X-Api-Key': config.radarr.apiKey } }); + return warnIfKeyNotChecked('Radarr', `${config.radarr.baseUrl}/api/v3/health`); }); } +// Sonarr and Radarr can skip authentication for local addresses, and then any +// key passes. Retry with a made-up key so a typo doesn't look like a success. +async function warnIfKeyNotChecked(label: string, url: string): Promise { + try { + await fetchJson(url, { headers: { 'X-Api-Key': 'aliceflix-invalid-key' } }); + return `Reachable, but ${label} accepts any API key from here, so the key can't be verified`; + } catch { + return undefined; + } +} + function testTmdb(config: AppConfig): Promise { return testService('tmdb', 'TMDb', true, [['token', getTmdbToken(config)]], async () => { // tmdbFetch swallows errors and returns null, so treat that as a failure. if (!await tmdbFetch(config, '/configuration')) { - throw new Error('TMDb rejected the token or is unreachable'); + throw new Error('TMDb rejected the key or is unreachable'); } }); } @@ -3931,11 +3944,17 @@ async function tmdbFetch(config: AppConfig, pathWithQuery: string): Promise>(`https://api.themoviedb.org/3${pathWithQuery}`, { - headers: { - Authorization: `Bearer ${token}` - } + return await fetchJson>(url.toString(), { + headers: isApiKey ? {} : { Authorization: `Bearer ${token}` } }); } catch (err) { console.error(`TMDb fetch failed for ${pathWithQuery}:`, err); diff --git a/src/App.tsx b/src/App.tsx index 566d110..d5e4abc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -343,12 +343,17 @@ function App() { async function handleSaveSettings(event: FormEvent) { event.preventDefault() + await saveSettings() + } + + async function saveSettings() { setBusy(true) setError('') setNotice('') try { const response = await api.saveSettings(config) setConfig(response.config) + setConnections(response.connections) await refreshBaseData() setNotice('Settings saved and services refreshed.') } catch (saveError) { @@ -510,6 +515,7 @@ function App() { config={config} connections={connections} onExit={() => setAuthState('profiles')} + onCheck={saveSettings} onSave={handleSaveSettings} options={options} updateConfig={updateConfig} @@ -605,6 +611,7 @@ function App() { busy={busy} config={config} connections={connections} + onCheck={saveSettings} onSave={handleSaveSettings} options={options} updateConfig={updateConfig} @@ -618,7 +625,6 @@ function App() { onOpenCard={(card, originRect) => setSelectedCard({ card, originRect: originRect ?? null })} onRequest={handleRequest} route={route} - tmdbToken={config.tmdb.bearerToken} /> ) : null} @@ -1275,7 +1281,6 @@ function HubPageView(props: { onRequest: (card: MediaCard) => Promise onOpenCard: (card: MediaCard, originRect?: ModalOriginRect | null) => void busy: boolean - tmdbToken: string }) { if (props.loading) { return @@ -1305,7 +1310,7 @@ function HubPageView(props: { return (
- + {props.hub.continueWatching?.length ? ( ) : null} @@ -1338,7 +1343,7 @@ function LibraryGrid(props: { ) } -function HeroShowcase({ hero, onOpenCard, tmdbToken }: { hero: MediaCard[]; onOpenCard: (card: MediaCard, originRect?: ModalOriginRect | null) => void; tmdbToken: string }) { +function HeroShowcase({ hero, onOpenCard }: { hero: MediaCard[]; onOpenCard: (card: MediaCard, originRect?: ModalOriginRect | null) => void }) { const [activeIndex, setActiveIndex] = useState(0) const [activeLogoUrl, setActiveLogoUrl] = useState('') const logoCacheRef = useRef(new Map()) @@ -1390,15 +1395,7 @@ function HeroShowcase({ hero, onOpenCard, tmdbToken }: { hero: MediaCard[]; onOp return } - const fetchImages = tmdbToken - ? fetch(`https://api.themoviedb.org/3/${mediaType}/${featured.tmdbId}/images`, { - headers: { - Authorization: `Bearer ${tmdbToken}`, - }, - }) - : fetch(`/api/tmdb/logo?tmdbId=${featured.tmdbId}&mediaType=${mediaType}`) - - void fetchImages + void fetch(`/api/tmdb/logo?tmdbId=${featured.tmdbId}&mediaType=${mediaType}`) .then(async (response) => { if (!response.ok) { throw new Error('Failed to load logo') @@ -1406,7 +1403,6 @@ function HeroShowcase({ hero, onOpenCard, tmdbToken }: { hero: MediaCard[]; onOp return response.json() as Promise<{ logos?: Array<{ file_path: string; iso_639_1: string | null }> - backdrops?: Array<{ file_path: string; iso_639_1: string | null }> }> }) .then((payload) => { @@ -1428,7 +1424,7 @@ function HeroShowcase({ hero, onOpenCard, tmdbToken }: { hero: MediaCard[]; onOp return () => { cancelled = true } - }, [featured, tmdbToken]) + }, [featured]) if (!featured) { return ( @@ -3909,6 +3905,7 @@ function AdministrationScreen(props: { updateConfig: (key: K, value: AppConfig[K]) => void options: ServiceOptionsResponse onSave: (event: FormEvent) => Promise + onCheck: () => Promise busy: boolean }) { return ( @@ -3921,18 +3918,15 @@ function AdministrationScreen(props: {

Administration

Settings

- @@ -3945,20 +3939,21 @@ function SettingsView(props: { updateConfig: (key: K, value: AppConfig[K]) => void options: ServiceOptionsResponse onSave: (event: FormEvent) => Promise + onCheck: () => Promise busy: boolean formId?: string - showSubmit?: boolean }) { + const check = { busy: props.busy, onCheck: props.onCheck } + return (
void props.onSave(event)}>
- {props.connections.map((connection) => ( + {SERVICE_KEYS.map((key) => getServiceStatus(props.connections, key) ?? notCheckedYet(key)).map((connection) => (
{connection.label} - {connection.optional ? Optional : null}
{connection.message}
@@ -3966,7 +3961,7 @@ function SettingsView(props: {
- + - + - + - + - + - + - {props.showSubmit !== false ?
- -
: null} ) } -function SettingsCard({ title, optional, children }: { title: string; optional?: boolean; children: ReactNode }) { +const SERVICE_KEYS: ConnectionStatus['key'][] = ['jellyfin', 'sonarr', 'radarr', 'tmdb', 'tvdb'] +const SERVICE_LABELS: Record = { jellyfin: 'Jellyfin', sonarr: 'Sonarr', radarr: 'Radarr', tmdb: 'TMDb', tvdb: 'TVDB' } + +// Stands in until the server has reported on a service, so the list is never empty. +function notCheckedYet(key: ConnectionStatus['key']): ConnectionStatus { + return { key, label: SERVICE_LABELS[key], ok: false, message: 'Not configured', configured: false, optional: key !== 'jellyfin' } +} + +function SettingsCard({ title, status, busy, onCheck, children }: { title: string; status?: ConnectionStatus; busy?: boolean; onCheck?: () => Promise; children: ReactNode }) { return (
-

- {title} - {optional ? Optional : null} -

+
+

{title}

+ {onCheck ? ( + + ) : null} +
{children}
+ {status ?
: null}
) } +// The result of the last check, which runs when the card's check button saves +// the settings, so the person can tell right there whether the URL and key work. +function ServiceCardStatus({ status }: { status: ConnectionStatus }) { + return ( +

+ + {status.message} +

+ ) +} + function ServiceFields(props: { baseUrl: string apiKey: string diff --git a/src/api.ts b/src/api.ts index 4e48793..895ff1c 100644 --- a/src/api.ts +++ b/src/api.ts @@ -82,7 +82,7 @@ export const api = { }), getSettings: () => request('/api/settings'), saveSettings: (payload: AppConfig) => - request<{ config: AppConfig }>('/api/settings', { + request<{ config: AppConfig; connections: ConnectionStatus[] }>('/api/settings', { method: 'PUT', body: JSON.stringify(payload), }), diff --git a/src/index.css b/src/index.css index bb1be45..d2a8664 100644 --- a/src/index.css +++ b/src/index.css @@ -3893,18 +3893,53 @@ img { font-size: 0.92rem; } -.settings-optional-tag { - margin-left: 0.55rem; - color: #72809c; - font-size: 0.68rem; - font-weight: 600; - letter-spacing: 0.14em; - text-transform: uppercase; - vertical-align: middle; +.settings-card-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.75rem; } -.settings-connection-label .settings-optional-tag { - margin-left: auto; +.settings-card-footer { + margin-top: 1rem; + padding-top: 0.85rem; + border-top: 1px solid rgba(255, 255, 255, 0.06); +} + +.settings-card-status { + display: flex; + align-items: center; + gap: 0.55rem; + margin: 0; + color: #c4cee0; + font-size: 0.9rem; +} + +.settings-card-check { + display: grid; + flex: none; + place-items: center; + width: 2.4rem; + height: 2.4rem; + border: 0; + border-radius: 999px; + background: #68d391; + color: #07120d; + transition: transform 180ms ease, filter 180ms ease; +} + +.settings-card-check svg { + width: 1.15rem; + height: 1.15rem; +} + +.settings-card-check:hover:not(:disabled) { + filter: brightness(1.08); + transform: scale(1.08); +} + +.settings-card-check:disabled { + opacity: 0.5; } .settings-card label, @@ -4200,10 +4235,11 @@ img { } .administration-header { - display: flex; + display: grid; + grid-template-columns: 2.9rem 1fr 2.9rem; align-items: center; - justify-content: space-between; gap: 1rem; + text-align: center; max-width: 76rem; margin: 0 auto 2rem; }