feat(server/web/coverart): manual Re-search missing art button

POST /api/admin/cover-sources/research bumps cover_art_sources_meta.
current_version unconditionally; the next enrichment pass re-eligibles
every 'none' row. Existing positively-sourced rows are not affected —
the version-mismatch eligibility rule only kicks in for 'none'.

Admin Cover Art panel gains a "Re-search missing art" button that
calls the endpoint and shows a confirmation toast. Operator's escape
hatch when:

- They've added a Last.fm key and want to retry failed rows
  immediately rather than waiting for the next scheduled scan.
- An upstream provider's catalog has updated (e.g. Deezer added a
  back-catalog import).
- They want to verify a fix end-to-end before the next scheduled
  scan fires.

SettingsService.BumpVersion (the unconditional version of T5's
BumpVersionIfProvidersChanged) is the single-call DB writer; both
endpoints route through it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 07:59:40 -04:00
parent 8f5ec4c304
commit c53bcb6c99
9 changed files with 224 additions and 1 deletions
@@ -0,0 +1,19 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { researchMissingArt } from './admin';
vi.mock('./client', () => ({
api: { get: vi.fn(), post: vi.fn(), patch: vi.fn() }
}));
import { api } from './client';
describe('admin research missing art API', () => {
beforeEach(() => vi.clearAllMocks());
it('researchMissingArt POSTs the correct path and returns version', async () => {
(api.post as unknown as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ version: 7 });
const got = await researchMissingArt();
expect(api.post).toHaveBeenCalledWith('/api/admin/cover-sources/research', {});
expect(got.version).toBe(7);
});
});
+11
View File
@@ -320,6 +320,17 @@ export async function testCoverProvider(id: string): Promise<TestCoverProviderRe
return api.post<TestCoverProviderResponse>(`/api/admin/cover-sources/${id}/test`, {});
}
// Re-search missing art --------------------------------------------------
export type ResearchMissingArtResponse = { version: number };
// Bumps cover_art_sources_meta.current_version. Every 'none' row becomes
// eligible for retry against the current provider chain on the next
// enrichment pass. Existing positively-sourced rows are not affected.
export async function researchMissingArt(): Promise<ResearchMissingArtResponse> {
return api.post<ResearchMissingArtResponse>('/api/admin/cover-sources/research', {});
}
// Settings rarely change in operator time. 60s staleTime; refetches
// on window focus + after any mutation rather than polling.
export function createCoverProvidersQuery() {
+24
View File
@@ -19,6 +19,7 @@
deleteQuarantineViaLidarr,
refetchMissingCovers,
triggerScan,
researchMissingArt,
type ScanSchedule,
type ScanScheduleMode
} from '$lib/api/admin';
@@ -315,6 +316,21 @@
let bulkBusy = $state(false);
let bulkResult = $state<string | null>(null);
// ---- Re-search missing art ----
let researchSaving = $state(false);
async function onResearchMissingArt() {
researchSaving = true;
try {
await researchMissingArt();
showToast('All previously-failed art will be re-attempted on the next scan.');
} catch (e) {
showToast(`Re-search failed: ${(e as { code?: string })?.code ?? 'unknown'}`);
} finally {
researchSaving = false;
}
}
async function onBulkRefetch() {
if (bulkBusy) return;
bulkBusy = true;
@@ -603,6 +619,14 @@
>
{bulkBusy ? 'Queueing…' : 'Refetch missing covers'}
</button>
<button
type="button"
onclick={onResearchMissingArt}
disabled={researchSaving}
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:bg-surface-hover hover:text-text-primary disabled:opacity-50"
>
{researchSaving ? 'Bumping…' : 'Re-search missing art'}
</button>
{#if coverage}
{#if coverage.total === 0}
+12 -1
View File
@@ -42,6 +42,7 @@ vi.mock('$lib/api/admin', async () => {
deleteQuarantineViaLidarr: vi.fn().mockResolvedValue({}),
triggerScan: vi.fn().mockResolvedValue({}),
refetchMissingCovers: vi.fn().mockResolvedValue({ queued: 0 }),
researchMissingArt: vi.fn().mockResolvedValue({ version: 1 }),
createScanScheduleQuery: vi.fn(() =>
readable({
data: {
@@ -111,7 +112,8 @@ import {
rejectRequest,
resolveQuarantine,
deleteQuarantineFile,
deleteQuarantineViaLidarr
deleteQuarantineViaLidarr,
researchMissingArt
} from '$lib/api/admin';
import OverviewPage from './+page.svelte';
@@ -264,6 +266,15 @@ describe('admin Overview page', () => {
expect(select.value).toBe('off');
});
test('renders Re-search missing art button and invokes on click', async () => {
setupOverview();
render(OverviewPage);
const btn = screen.getByRole('button', { name: /re-search missing art/i });
expect(btn).toBeInTheDocument();
await fireEvent.click(btn);
expect(researchMissingArt).toHaveBeenCalled();
});
test('Library scan card shows Processing badge when library tally is populated and in-flight', async () => {
const { readable } = await import('svelte/store');
(createScanStatusQuery as ReturnType<typeof vi.fn>).mockReturnValueOnce(