Fix: media index build never starts (blocking Jellyfin dependency)

The build endpoint had Depends(get_jellyfin_client) and Depends(get_user_id)
which executed BEFORE the function body. If Jellyfin was unreachable, these
raised HTTPException(503), the function never ran, and the worker was never
started. The frontend mutation had no onError handler, so the failure was
completely silent — the button briefly showed 'Building...' then reverted
to 'Build index' with zero feedback.

Backend fix: removed the Jellyfin dependencies from post_build_index.
The worker subprocess resolves its own Jellyfin connection via
_resolve_jellyfin(service_id) — the endpoint just needs to start the
worker process. The libraries count starts at 0 and gets updated by
the worker once it connects.

Frontend fix: added onError to useBuildIndex that invalidates the status
query (so the UI reflects the non-building state). MediaTab now displays
the build error inline: 'Build failed: <message>' next to the button.

283 backend tests pass (updated build test for new no-dependency flow);
128 frontend tests pass; ruff/eslint clean.
This commit is contained in:
Developer
2026-07-06 15:25:48 +00:00
parent 57fe04ae7b
commit 787f46700f
5 changed files with 26 additions and 9 deletions
@@ -237,8 +237,9 @@ export function WidgetConfigDialog({
useEffect(() => {
if (open && editWidgetId) {
// Search both owned widgets and referenced widgets.
const target = instances.find((w) => w.id === editWidgetId)
?? references.find((r) => r.widget.id === editWidgetId)?.widget;
const target =
instances.find((w) => w.id === editWidgetId) ??
references.find((r) => r.widget.id === editWidgetId)?.widget;
if (target) {
startEdit(target);
}
+4
View File
@@ -54,6 +54,10 @@ export function useBuildIndex(jellyfinServiceId?: string) {
onSuccess: () => {
invalidateMedia(queryClient);
},
onError: () => {
// Invalidate status so the UI reflects the current (non-building) state.
invalidateMedia(queryClient);
},
});
}
@@ -352,6 +352,11 @@ export function MediaTab({ instance }: { instance: ServiceInstance }) {
>
{buildIndex.isPending || buildRunning ? "Building..." : "Build index"}
</Button>
{buildIndex.isError ? (
<span className="text-sm text-destructive">
Build failed: {buildIndex.error instanceof Error ? buildIndex.error.message : "Unknown error"}
</span>
) : null}
{buildRunning && (
<>
<Button