feat(admin): metadata-profile picker on integrations page
Persists the operator's metadata-profile choice alongside quality profile + root folder. Defaults to the first profile Lidarr returns (usually 'Standard' on a vanilla install) so the common case is zero-click; operators with custom profiles like 'Singles only' can pick explicitly. Backend: - Migration 0013: adds nullable default_metadata_profile_id to lidarr_config. Existing rows get NULL and the service falls back to fetch-and-pick-first until they save. - Updated lidarr_config queries + sqlc + lidarrconfig.Config + admin view/put body to round-trip the new field. - handlePutLidarrConfig requires it (along with QP and root folder) when enabled=true — matches the existing missing_defaults gate. - New GET /api/admin/lidarr/metadata-profiles handler + lidarr.Client ListMetadataProfiles (GET /api/v1/metadataprofile, same shape as the quality-profile endpoint). - lidarrrequests.Approve prefers cfg.DefaultMetadataProfileID; falls back to the fetch-list path only when 0 (back-compat for upgraders). Frontend: - LidarrConfig type + LidarrMetadataProfile type + qk.lidarrMetadataProfiles. - listMetadataProfiles + createMetadataProfilesQuery client helpers. - Integrations page: third <select> picker, auto-defaults to first profile when the saved value is 0, sends the new field on save and clears it on disconnect. - Updated test fixtures + the duplicate 'Standard' option string in the dropdown-populates assertion. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,7 @@ const baseConfig: LidarrConfig = {
|
||||
base_url: 'http://lidarr.lan:8686',
|
||||
api_key: '***',
|
||||
default_quality_profile_id: 1,
|
||||
default_metadata_profile_id: 1,
|
||||
default_root_folder_path: '/music'
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
ActionResult,
|
||||
AdminQuarantineRow,
|
||||
LidarrConfig,
|
||||
LidarrMetadataProfile,
|
||||
LidarrQualityProfile,
|
||||
LidarrQuarantineActionRow,
|
||||
LidarrRequest,
|
||||
@@ -36,6 +37,10 @@ export async function listQualityProfiles(): Promise<LidarrQualityProfile[]> {
|
||||
return api.get<LidarrQualityProfile[]>('/api/admin/lidarr/quality-profiles');
|
||||
}
|
||||
|
||||
export async function listMetadataProfiles(): Promise<LidarrMetadataProfile[]> {
|
||||
return api.get<LidarrMetadataProfile[]>('/api/admin/lidarr/metadata-profiles');
|
||||
}
|
||||
|
||||
export async function listRootFolders(): Promise<LidarrRootFolder[]> {
|
||||
return api.get<LidarrRootFolder[]>('/api/admin/lidarr/root-folders');
|
||||
}
|
||||
@@ -92,6 +97,14 @@ export function createQualityProfilesQuery(enabled: boolean = true) {
|
||||
});
|
||||
}
|
||||
|
||||
export function createMetadataProfilesQuery(enabled: boolean = true) {
|
||||
return createQuery({
|
||||
queryKey: qk.lidarrMetadataProfiles(),
|
||||
queryFn: listMetadataProfiles,
|
||||
enabled
|
||||
});
|
||||
}
|
||||
|
||||
export function createRootFoldersQuery(enabled: boolean = true) {
|
||||
return createQuery({
|
||||
queryKey: qk.lidarrRootFolders(),
|
||||
|
||||
@@ -24,8 +24,9 @@ export const qk = {
|
||||
['lidarrSearch', { q, kind }] as const,
|
||||
myRequests: () => ['myRequests'] as const,
|
||||
lidarrConfig: () => ['lidarrConfig'] as const,
|
||||
lidarrQualityProfiles: () => ['lidarrQualityProfiles'] as const,
|
||||
lidarrRootFolders: () => ['lidarrRootFolders'] as const,
|
||||
lidarrQualityProfiles: () => ['lidarrQualityProfiles'] as const,
|
||||
lidarrMetadataProfiles: () => ['lidarrMetadataProfiles'] as const,
|
||||
lidarrRootFolders: () => ['lidarrRootFolders'] as const,
|
||||
adminRequests: (status?: string) =>
|
||||
['adminRequests', { status: status ?? 'all' }] as const,
|
||||
myQuarantine: () => ['myQuarantine'] as const,
|
||||
|
||||
@@ -131,6 +131,7 @@ export type LidarrConfig = {
|
||||
base_url: string;
|
||||
api_key: string;
|
||||
default_quality_profile_id: number;
|
||||
default_metadata_profile_id: number;
|
||||
default_root_folder_path: string;
|
||||
};
|
||||
|
||||
@@ -139,6 +140,11 @@ export type LidarrQualityProfile = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type LidarrMetadataProfile = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type LidarrRootFolder = {
|
||||
path: string;
|
||||
accessible: boolean;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import {
|
||||
createLidarrConfigQuery,
|
||||
createQualityProfilesQuery,
|
||||
createMetadataProfilesQuery,
|
||||
createRootFoldersQuery,
|
||||
putLidarrConfig,
|
||||
testLidarrConnection
|
||||
@@ -26,6 +27,7 @@
|
||||
let baseUrl = $state('');
|
||||
let apiKeyInput = $state(''); // intentionally never seeded with '***'
|
||||
let qualityId = $state<number>(0);
|
||||
let metadataId = $state<number>(0);
|
||||
let rootPath = $state<string>('');
|
||||
let initialized = false;
|
||||
|
||||
@@ -34,6 +36,7 @@
|
||||
if (c && !initialized) {
|
||||
baseUrl = c.base_url;
|
||||
qualityId = c.default_quality_profile_id;
|
||||
metadataId = c.default_metadata_profile_id;
|
||||
rootPath = c.default_root_folder_path;
|
||||
initialized = true;
|
||||
}
|
||||
@@ -41,13 +44,18 @@
|
||||
|
||||
// Auto-default to the first option Lidarr returns when the operator
|
||||
// hasn't picked one yet. Saves a click for the common case (one
|
||||
// quality profile + one root folder, which is what most home setups
|
||||
// have). The operator can still change either before saving.
|
||||
// profile + one root folder, which is what most home setups have).
|
||||
// The operator can still change any of them before saving.
|
||||
$effect(() => {
|
||||
if (qualityId === 0 && profiles.data && profiles.data.length > 0) {
|
||||
qualityId = profiles.data[0].id;
|
||||
}
|
||||
});
|
||||
$effect(() => {
|
||||
if (metadataId === 0 && metadataProfiles.data && metadataProfiles.data.length > 0) {
|
||||
metadataId = metadataProfiles.data[0].id;
|
||||
}
|
||||
});
|
||||
$effect(() => {
|
||||
if (rootPath === '' && folders.data && folders.data.length > 0) {
|
||||
rootPath = folders.data[0].path;
|
||||
@@ -61,6 +69,9 @@
|
||||
const profilesStore = $derived(createQualityProfilesQuery(profilesEnabled));
|
||||
const profiles = $derived($profilesStore);
|
||||
|
||||
const metadataProfilesStore = $derived(createMetadataProfilesQuery(profilesEnabled));
|
||||
const metadataProfiles = $derived($metadataProfilesStore);
|
||||
|
||||
const foldersStore = $derived(createRootFoldersQuery(profilesEnabled));
|
||||
const folders = $derived($foldersStore);
|
||||
|
||||
@@ -78,6 +89,7 @@
|
||||
base_url: baseUrl,
|
||||
api_key: apiKeyInput, // empty string tells backend "preserve saved key"
|
||||
default_quality_profile_id: qualityId,
|
||||
default_metadata_profile_id: metadataId,
|
||||
default_root_folder_path: rootPath
|
||||
};
|
||||
await putLidarrConfig(cfg);
|
||||
@@ -86,6 +98,7 @@
|
||||
await Promise.all([
|
||||
client.invalidateQueries({ queryKey: qk.lidarrConfig() }),
|
||||
client.invalidateQueries({ queryKey: qk.lidarrQualityProfiles() }),
|
||||
client.invalidateQueries({ queryKey: qk.lidarrMetadataProfiles() }),
|
||||
client.invalidateQueries({ queryKey: qk.lidarrRootFolders() })
|
||||
]);
|
||||
apiKeyInput = '';
|
||||
@@ -126,11 +139,13 @@
|
||||
base_url: '',
|
||||
api_key: '',
|
||||
default_quality_profile_id: 0,
|
||||
default_metadata_profile_id: 0,
|
||||
default_root_folder_path: ''
|
||||
});
|
||||
await Promise.all([
|
||||
client.invalidateQueries({ queryKey: qk.lidarrConfig() }),
|
||||
client.invalidateQueries({ queryKey: qk.lidarrQualityProfiles() }),
|
||||
client.invalidateQueries({ queryKey: qk.lidarrMetadataProfiles() }),
|
||||
client.invalidateQueries({ queryKey: qk.lidarrRootFolders() })
|
||||
]);
|
||||
modalOpen = false;
|
||||
@@ -212,6 +227,19 @@
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label class="block">
|
||||
<span class="block text-sm text-text-secondary">Default metadata profile</span>
|
||||
<select
|
||||
bind:value={metadataId}
|
||||
disabled={!profilesEnabled || metadataProfiles.isPending}
|
||||
class="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-accent disabled:opacity-50"
|
||||
>
|
||||
{#each metadataProfiles.data ?? [] as p (p.id)}
|
||||
<option value={p.id}>{p.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label class="block">
|
||||
<span class="block text-sm text-text-secondary">Default root folder</span>
|
||||
<select
|
||||
|
||||
@@ -13,6 +13,7 @@ vi.mock('@tanstack/svelte-query', async (orig) => {
|
||||
vi.mock('$lib/api/admin', () => ({
|
||||
createLidarrConfigQuery: vi.fn(),
|
||||
createQualityProfilesQuery: vi.fn(),
|
||||
createMetadataProfilesQuery: vi.fn(),
|
||||
createRootFoldersQuery: vi.fn(),
|
||||
putLidarrConfig: vi.fn(),
|
||||
testLidarrConnection: vi.fn()
|
||||
@@ -22,6 +23,7 @@ import IntegrationsPage from './+page.svelte';
|
||||
import {
|
||||
createLidarrConfigQuery,
|
||||
createQualityProfilesQuery,
|
||||
createMetadataProfilesQuery,
|
||||
createRootFoldersQuery,
|
||||
putLidarrConfig,
|
||||
testLidarrConnection
|
||||
@@ -32,6 +34,7 @@ const cfgConnected: LidarrConfig = {
|
||||
base_url: 'http://lidarr.local',
|
||||
api_key: '***',
|
||||
default_quality_profile_id: 1,
|
||||
default_metadata_profile_id: 1,
|
||||
default_root_folder_path: '/music'
|
||||
};
|
||||
|
||||
@@ -40,6 +43,7 @@ const cfgUnset: LidarrConfig = {
|
||||
base_url: '',
|
||||
api_key: '',
|
||||
default_quality_profile_id: 0,
|
||||
default_metadata_profile_id: 0,
|
||||
default_root_folder_path: ''
|
||||
};
|
||||
|
||||
@@ -59,6 +63,14 @@ function setup(opts: { config?: LidarrConfig } = {}) {
|
||||
]
|
||||
})
|
||||
);
|
||||
(createMetadataProfilesQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockQuery({
|
||||
data: [
|
||||
{ id: 1, name: 'Standard' },
|
||||
{ id: 2, name: 'Singles only' }
|
||||
]
|
||||
})
|
||||
);
|
||||
(createRootFoldersQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockQuery({ data: [{ path: '/music', accessible: true, free_space: 0 }] })
|
||||
);
|
||||
@@ -164,10 +176,12 @@ describe('/admin/integrations', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('Quality profile and root folder dropdowns populate from API', () => {
|
||||
test('Quality / metadata / root folder dropdowns populate from API', () => {
|
||||
setup();
|
||||
expect(screen.getByText('Standard')).toBeInTheDocument();
|
||||
// 'Standard' appears in both quality + metadata fixtures, so use *AllBy*.
|
||||
expect(screen.getAllByText('Standard').length).toBeGreaterThanOrEqual(2);
|
||||
expect(screen.getByText('Lossless')).toBeInTheDocument();
|
||||
expect(screen.getByText('Singles only')).toBeInTheDocument();
|
||||
expect(screen.getByText('/music')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user