From a110c89e081b253e411b2047e02e42b10da5aa3d Mon Sep 17 00:00:00 2001 From: WonderAliceUwU Date: Wed, 21 Oct 2026 20:10:31 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20feat:=20handle=20missing?= =?UTF-8?q?=20or=20unreachable=20services?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jellyfin is required: when it is not set up or unreachable, show a screen saying so with a retry instead of an empty profile list. Sonarr and Radarr are optional, so hide the actions and pages that need them when they are not configured, and keep options and the dashboard loading when one is down. Connection statuses now say whether a service is configured, optional or half filled in. The status dot only turns red for real failures, and Settings marks optional services and shows unconfigured ones in grey. --- server/index.ts | 16 ++-- server/lib/services.ts | 157 +++++++++++++-------------------------- shared/contracts.ts | 6 ++ src/App.tsx | 164 ++++++++++++++++++++++++++++++++++++----- src/index.css | 42 +++++++++++ 5 files changed, 254 insertions(+), 131 deletions(-) diff --git a/server/index.ts b/server/index.ts index 26de77a..0befcc8 100644 --- a/server/index.ts +++ b/server/index.ts @@ -180,16 +180,20 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse): } if (url.pathname === '/api/auth/profiles' && method === 'GET') { + let config: AppConfig; try { - const config = await readConfig(); - const [jellyfinUsers, connections] = await Promise.all([ - loadJellyfinUsers(config.jellyfin.baseUrl, config.jellyfin.apiKey), - getConnectionStatuses(config) - ]); - sendJson(response, 200, { jellyfinUsers, connections }); + config = await readConfig(); } catch { sendJson(response, 409, { error: 'An administrator must sign in once to migrate the existing configuration.' }); + return; } + // A Jellyfin outage is reported through the connection status, so the + // client can show it instead of an empty profile list. + const [jellyfinUsers, connections] = await Promise.all([ + loadJellyfinUsers(config.jellyfin.baseUrl, config.jellyfin.apiKey).catch(() => []), + getConnectionStatuses(config) + ]); + sendJson(response, 200, { jellyfinUsers, connections }); return; } diff --git a/server/lib/services.ts b/server/lib/services.ts index ac1cda2..6cdff59 100644 --- a/server/lib/services.ts +++ b/server/lib/services.ts @@ -435,12 +435,14 @@ export async function getServiceOptions(config: AppConfig): Promise []), + getSonarrRootFolders(config).catch(() => []), + getSonarrQualityProfiles(config).catch(() => []), + getSonarrLanguageProfiles(config).catch(() => []), + getRadarrRootFolders(config).catch(() => []), + getRadarrQualityProfiles(config).catch(() => []) ]); return { @@ -558,7 +560,9 @@ export async function authenticateJellyfinUser(config: AppConfig, userId: string export async function getDashboard(config: AppConfig): Promise { const [connections, library, downloads, tmdb] = await Promise.all([ getConnectionStatuses(config), - getLibrarySnapshot(config), + // If Jellyfin is down the client shows its unavailable screen from the + // connection status, so don't fail the whole dashboard here. + getLibrarySnapshot(config).catch(() => ({ continueWatching: [], recentlyAdded: [], allItems: [] })), getDownloads(config), getTmdbSnapshot(config) ]); @@ -3757,131 +3761,74 @@ async function getRadarrCalendar(config: AppConfig, start: Date, end: Date): Pro ) } -async function testJellyfin(config: AppConfig): Promise { - if (!config.jellyfin.baseUrl || !config.jellyfin.apiKey) { - return { - key: 'jellyfin', - label: 'Jellyfin', - ok: false, - message: 'Not configured' - }; +async function testService( + key: ConnectionStatus['key'], + label: string, + optional: boolean, + required: Array<[name: string, value: string]>, + check: () => Promise +): Promise { + const missing = required.filter(([, value]) => !value.trim()).map(([name]) => name); + if (missing.length === required.length) { + return { key, label, ok: false, message: 'Not configured', configured: false, optional }; + } + if (missing.length) { + return { key, label, ok: false, message: `Incomplete: missing ${missing.join(' and ')}`, configured: false, optional, incomplete: true }; } try { + await check(); + return { key, label, ok: true, message: 'Connected', configured: true, optional }; + } catch (error) { + const message = errorMessage(error); + // Node reports network errors as a bare "fetch failed". + return { key, label, ok: false, message: message === 'fetch failed' ? `Can't reach ${label}` : message, configured: true, optional }; + } +} + +function testJellyfin(config: AppConfig): Promise { + return testService('jellyfin', 'Jellyfin', false, [['URL', config.jellyfin.baseUrl], ['API key', config.jellyfin.apiKey]], async () => { await fetchJson(`${config.jellyfin.baseUrl}/System/Info`, { headers: { Authorization: `MediaBrowser Token="${config.jellyfin.apiKey}"` } }); - return { key: 'jellyfin', label: 'Jellyfin', ok: true, message: 'Connected' }; - } catch (error) { - return { - key: 'jellyfin', - label: 'Jellyfin', - ok: false, - message: errorMessage(error) - }; - } + }); } -async function testSonarr(config: AppConfig): Promise { - if (!config.sonarr.baseUrl || !config.sonarr.apiKey) { - return { - key: 'sonarr', - label: 'Sonarr', - ok: false, - message: 'Not configured' - }; - } - - try { +function testSonarr(config: AppConfig): Promise { + return testService('sonarr', 'Sonarr', true, [['URL', config.sonarr.baseUrl], ['API key', config.sonarr.apiKey]], async () => { await fetchJson(`${config.sonarr.baseUrl}/api/v3/health`, { headers: { 'X-Api-Key': config.sonarr.apiKey } }); - return { key: 'sonarr', label: 'Sonarr', ok: true, message: 'Connected' }; - } catch (error) { - return { - key: 'sonarr', - label: 'Sonarr', - ok: false, - message: errorMessage(error) - }; - } + }); } -async function testRadarr(config: AppConfig): Promise { - if (!config.radarr.baseUrl || !config.radarr.apiKey) { - return { - key: 'radarr', - label: 'Radarr', - ok: false, - message: 'Not configured' - }; - } - - try { +function testRadarr(config: AppConfig): Promise { + return testService('radarr', 'Radarr', true, [['URL', config.radarr.baseUrl], ['API key', config.radarr.apiKey]], async () => { await fetchJson(`${config.radarr.baseUrl}/api/v3/health`, { headers: { 'X-Api-Key': config.radarr.apiKey } }); - return { key: 'radarr', label: 'Radarr', ok: true, message: 'Connected' }; - } catch (error) { - return { - key: 'radarr', - label: 'Radarr', - ok: false, - message: errorMessage(error) - }; - } + }); } -async function testTmdb(config: AppConfig): Promise { - if (!getTmdbToken(config)) { - return { - key: 'tmdb', - label: 'TMDb', - ok: false, - message: 'Missing token' - }; - } - - try { - await tmdbFetch(config, '/configuration'); - return { key: 'tmdb', label: 'TMDb', ok: true, message: 'Connected' }; - } catch (error) { - return { - key: 'tmdb', - label: 'TMDb', - ok: false, - message: errorMessage(error) - }; - } +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'); + } + }); } -async function testTvdb(config: AppConfig): Promise { - if (!getTvdbApiKey(config)) { - return { - key: 'tvdb', - label: 'TVDB', - ok: false, - message: 'Missing API key' - }; - } - - try { +function testTvdb(config: AppConfig): Promise { + return testService('tvdb', 'TVDB', true, [['API key', getTvdbApiKey(config)]], async () => { await getTvdbToken(config); - return { key: 'tvdb', label: 'TVDB', ok: true, message: 'Connected' }; - } catch (error) { - return { - key: 'tvdb', - label: 'TVDB', - ok: false, - message: errorMessage(error) - }; - } + }); } async function jellyfinFetch(config: AppConfig, pathWithQuery: string): Promise { diff --git a/shared/contracts.ts b/shared/contracts.ts index 0a482e9..d2c6a44 100644 --- a/shared/contracts.ts +++ b/shared/contracts.ts @@ -86,6 +86,12 @@ export interface ConnectionStatus { label: string; ok: boolean; message: string; + /** Every field the service needs is filled in. */ + configured: boolean; + /** The app works without it; only Jellyfin is required. */ + optional: boolean; + /** Some of its fields are filled in but not all of them. */ + incomplete?: boolean; } export interface DiskSpaceStatus { diff --git a/src/App.tsx b/src/App.tsx index d2bb019..566d110 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -286,6 +286,24 @@ function App() { } } + async function handleRetryJellyfin() { + setBusy(true) + setError('') + try { + if (authState === 'app') { + await refreshBaseData() + } else { + const profiles = await api.getProfiles() + setOptions((current) => ({ ...current, jellyfinUsers: profiles.jellyfinUsers })) + setConnections(profiles.connections) + } + } catch (retryError) { + setError(retryError instanceof Error ? retryError.message : 'Failed to reach Jellyfin.') + } finally { + setBusy(false) + } + } + async function handleLoadJellyfinUsers() { setJellyfinUsersBusy(true) setError('') @@ -454,15 +472,31 @@ function App() { ) } + const jellyfinStatus = getServiceStatus(connections, 'jellyfin') + const openAdministration = () => setAuthState(sessionRole === 'admin' ? 'admin' : 'login') + + // Jellyfin is required: without it there are no profiles or library to show. + if ((authState === 'profiles' || (authState === 'app' && jellyfinStatus?.configured)) && isJellyfinUnavailable(connections)) { + return ( + void handleRetryJellyfin()} + status={jellyfinStatus} + /> + ) + } + if (authState === 'profiles') { return ( !connection.ok)} + hasServiceFailure={hasFailingService(connections)} error={error} notice={notice} - onAdmin={() => setAuthState(sessionRole === 'admin' ? 'admin' : 'login')} + onAdmin={openAdministration} onSelectUser={handleSelectJellyfinUser} users={options.jellyfinUsers} /> @@ -509,10 +543,10 @@ function App() { !connection.ok)} + hasServiceFailure={hasFailingService(connections)} error={error} notice={notice} - onAdmin={() => setAuthState(sessionRole === 'admin' ? 'admin' : 'login')} + onAdmin={openAdministration} onContinue={() => void transitionEntryStage('dashboard')} onSelectUser={handleSelectJellyfinUser} users={options.jellyfinUsers} @@ -547,8 +581,14 @@ function App() { {error ?

{error}

: null} - {route === 'calendar' ? setSelectedCard({ card, originRect: originRect ?? null })} /> : null} - {route === 'downloads' ? : null} + {(route === 'calendar' || route === 'downloads') && !isRouteAvailable(route, connections) ? ( + + ) : null} + {route === 'calendar' && isRouteAvailable(route, connections) ? setSelectedCard({ card, originRect: originRect ?? null })} /> : null} + {route === 'downloads' && isRouteAvailable(route, connections) ? : null} {route === 'search' ? ( ) : null} @@ -622,7 +663,7 @@ function Sidebar(props: { onExitProfile: () => void }) { const [menuOpen, setMenuOpen] = useState(false) - const hasServiceFailure = props.connections.some((connection) => !connection.ok) + const hasServiceFailure = hasFailingService(props.connections) useEffect(() => { function closeOnEscape(event: KeyboardEvent) { @@ -679,7 +720,7 @@ function Sidebar(props: {
- {topSidebarItems.map((item) => ( + {topSidebarItems.filter((item) => isRouteAvailable(item.route, props.connections)).map((item) => ( + ) : null} +
+
+ +
+ + ) +} + function ProfileAvatar({ user }: { user: SelectOption }) { return
{user.imageUrl ? : user.label.slice(0, 1).toUpperCase()}
} @@ -1570,6 +1688,8 @@ function TitleDetailsModal(props: { onRequest: (card: MediaCard, qualityProfileId?: number, seasonNumber?: number) => Promise currentUser: string | null qualityProfiles: { sonarr: SelectOption[]; radarr: SelectOption[] } + /** Which download services are configured; their actions are hidden otherwise. */ + services: { sonarr: boolean; radarr: boolean } }) { const [details, setDetails] = useState(null) const [detailsLoading, setDetailsLoading] = useState(true) @@ -1903,7 +2023,7 @@ function TitleDetailsModal(props: { : details?.requestStatus || 'idle' const movieRequestProgress = details?.requestProgress || 0 const isMovieRequestActive = details?.mediaType === 'movie' && (movieRequestStatus === 'processing' || movieRequestStatus === 'downloading') - const canDeleteMovieAction = Boolean(details?.mediaType === 'movie' && details.radarrMovieId) + const canDeleteMovieAction = Boolean(props.services.radarr && details?.mediaType === 'movie' && details.radarrMovieId) const activeSeasonNumber = effectiveActiveSeasonMeta?.seasonNumber const activeSeasonDownloadStatus = effectiveActiveSeasonMeta?.downloadStatus || 'idle' const currentSeasonIndex = details?.seasons.findIndex((season) => season.id === seasonValue) ?? -1 @@ -1921,7 +2041,7 @@ function TitleDetailsModal(props: { } : episode) : [] - const canDownloadSeasonAction = Boolean( + const canDownloadSeasonAction = props.services.sonarr && Boolean( activeSeasonDownloadStatus === 'processing' || activeSeasonDownloadStatus === 'downloading' || (details?.sonarrSeriesId && typeof activeSeasonNumber === 'number' && activeSeasonNumber > 0) @@ -1932,7 +2052,7 @@ function TitleDetailsModal(props: { const isSeasonFullyDownloadedExceptUnaired = episodesForSeason.length > 0 && episodesForSeason.every( (episode) => episode.availability === 'available' || episode.availability === 'unaired' ); - const canDeleteSeasonAction = (Boolean(effectiveActiveSeasonMeta?.canDelete) || isSeasonFullyDownloadedExceptUnaired); + const canDeleteSeasonAction = props.services.sonarr && (Boolean(effectiveActiveSeasonMeta?.canDelete) || isSeasonFullyDownloadedExceptUnaired); const shouldShowDownloadSeasonAction = canDownloadSeasonAction && !canDeleteSeasonAction; useEffect(() => { @@ -2484,7 +2604,7 @@ function TitleDetailsModal(props: { ) : null} - {!canPlay && canRequest && details?.mediaType !== 'series' ? ( + {!canPlay && canRequest && props.services.radarr && details?.mediaType !== 'series' ? ( isMovieRequestActive ? ( movieRequestStatus === 'downloading' ? (
{episode.title}
- {episode.canDownload || episode.downloadStatus === 'processing' || episode.downloadStatus === 'downloading' ? ( + {props.services.sonarr && (episode.canDownload || episode.downloadStatus === 'processing' || episode.downloadStatus === 'downloading') ? ( episode.downloadStatus === 'downloading' ? ( (
- + {connection.label} + {connection.optional ? Optional : null}
{connection.message}
@@ -3865,7 +3986,7 @@ function SettingsView(props: { /> - + - + - + - +