feat(admin): switches for ListenBrainz similarity and MusicBrainz track lists
release / go (push) Successful in 1m50s
release / web (push) Successful in 1m15s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m11s
release / android (push) Successful in 4m33s
release / Build signed APK (push) Successful in 4m40s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 22s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 1m50s
release / web (push) Successful in 1m15s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m11s
release / android (push) Successful in 4m33s
release / Build signed APK (push) Successful in 4m40s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 22s
release / Verify release artifacts (tag releases only) (push) Skipped
Both lookups ran with no way to stop them. Admin › Metadata sources now has an "Other lookups" group with a switch each, both on by default (lookup_settings, migration 0111). Off, the similarity worker asks ListenBrainz nothing and still links what it already fetched; the duplicate resolver gets ErrLookupOff and decides from the track lists it already has. The setting is backed up, and docs/security.md names the switches. docs/security.md also says every account but the first needs an invite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -318,6 +318,24 @@ export async function updateLoudnessSettings(s: LoudnessSettings): Promise<Loudn
|
||||
return api.put<LoudnessSettings>('/api/admin/library/loudness-settings', s);
|
||||
}
|
||||
|
||||
// Outside lookups no metadata source covers ---------------------------
|
||||
|
||||
/** Switches for ListenBrainz's similar songs and artists (radio and the
|
||||
* mixes) and MusicBrainz's album track lists (the duplicate resolver).
|
||||
* Both are on unless an admin turns them off. */
|
||||
export type LookupSettings = {
|
||||
listenbrainz_similarity: boolean;
|
||||
musicbrainz_track_lists: boolean;
|
||||
};
|
||||
|
||||
export async function getLookupSettings(): Promise<LookupSettings> {
|
||||
return api.get<LookupSettings>('/api/admin/lookup-settings');
|
||||
}
|
||||
|
||||
export async function updateLookupSettings(s: LookupSettings): Promise<LookupSettings> {
|
||||
return api.put<LookupSettings>('/api/admin/lookup-settings', s);
|
||||
}
|
||||
|
||||
// The library's folders -----------------------------------------------
|
||||
|
||||
export type LibraryFolder = {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { getLookupSettings, updateLookupSettings, type LookupSettings } from '#lib/api/admin.js';
|
||||
import { errMessage } from '#lib/api/errors.js';
|
||||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||
import SettingsGroup from '#lib/components/settings/SettingsGroup.svelte';
|
||||
import SettingRow from '#lib/components/settings/SettingRow.svelte';
|
||||
|
||||
// The outside lookups that no cover art or tag source covers, each with
|
||||
// a switch that saves as it is flipped. Both start on; turning one off
|
||||
// stops the requests and keeps what was already fetched.
|
||||
|
||||
let settings = $state<LookupSettings | null>(null);
|
||||
let saving = $state(false);
|
||||
let loadError = $state(false);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
settings = await getLookupSettings();
|
||||
loadError = false;
|
||||
} catch {
|
||||
loadError = true;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(load);
|
||||
|
||||
async function flip(key: keyof LookupSettings, on: boolean) {
|
||||
if (!settings) return;
|
||||
const before = settings;
|
||||
settings = { ...settings, [key]: on };
|
||||
saving = true;
|
||||
try {
|
||||
settings = await updateLookupSettings(settings);
|
||||
} catch (e) {
|
||||
settings = before;
|
||||
pushToast(`Couldn't save: ${errMessage(e)}`, 'error');
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
const rows: { key: keyof LookupSettings; label: string; hint: string }[] = [
|
||||
{
|
||||
key: 'listenbrainz_similarity',
|
||||
label: 'ListenBrainz similar songs',
|
||||
hint: 'Which songs and artists go together, for radio and the mixes.'
|
||||
},
|
||||
{
|
||||
key: 'musicbrainz_track_lists',
|
||||
label: 'MusicBrainz track lists',
|
||||
hint: "An album's songs, so the duplicate resolver can spot a misfiled copy."
|
||||
}
|
||||
];
|
||||
</script>
|
||||
|
||||
<SettingsGroup title="Other lookups" hint="Asked in the background; what was already fetched is kept.">
|
||||
{#if settings}
|
||||
{#each rows as row (row.key)}
|
||||
<SettingRow label={row.label} hint={row.hint} for="lookup-{row.key}">
|
||||
<input
|
||||
id="lookup-{row.key}"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
aria-checked={settings[row.key]}
|
||||
checked={settings[row.key]}
|
||||
disabled={saving}
|
||||
onchange={(e) => flip(row.key, e.currentTarget.checked)}
|
||||
class="h-4 w-4 cursor-pointer accent-accent"
|
||||
/>
|
||||
</SettingRow>
|
||||
{/each}
|
||||
{:else if loadError}
|
||||
<p class="px-4 py-3 text-sm text-error-fg">
|
||||
Couldn't load these settings.
|
||||
<button type="button" class="underline hover:no-underline" onclick={load}>Try again</button>
|
||||
</p>
|
||||
{:else}
|
||||
<p class="px-4 py-3 text-sm text-text-secondary">Loading…</p>
|
||||
{/if}
|
||||
</SettingsGroup>
|
||||
@@ -0,0 +1,50 @@
|
||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/svelte';
|
||||
|
||||
vi.mock('#lib/api/admin.js', () => ({
|
||||
getLookupSettings: vi.fn(),
|
||||
updateLookupSettings: vi.fn()
|
||||
}));
|
||||
vi.mock('#lib/stores/toast.svelte.js', () => ({ pushToast: vi.fn() }));
|
||||
|
||||
import LookupSettingsCard from './LookupSettingsCard.svelte';
|
||||
import { getLookupSettings, updateLookupSettings } from '#lib/api/admin.js';
|
||||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||
|
||||
const bothOn = { listenbrainz_similarity: true, musicbrainz_track_lists: true };
|
||||
|
||||
afterEach(() => vi.clearAllMocks());
|
||||
|
||||
describe('LookupSettingsCard', () => {
|
||||
test('shows both lookups on, and saves a switch as it is flipped', async () => {
|
||||
vi.mocked(getLookupSettings).mockResolvedValue(bothOn);
|
||||
vi.mocked(updateLookupSettings).mockImplementation(async (s) => s);
|
||||
render(LookupSettingsCard);
|
||||
|
||||
const lb = await screen.findByRole('switch', { name: /listenbrainz similar songs/i });
|
||||
const mb = screen.getByRole('switch', { name: /musicbrainz track lists/i });
|
||||
expect(lb).toBeChecked();
|
||||
expect(mb).toBeChecked();
|
||||
|
||||
await fireEvent.click(lb);
|
||||
await waitFor(() =>
|
||||
expect(updateLookupSettings).toHaveBeenCalledWith({
|
||||
listenbrainz_similarity: false,
|
||||
musicbrainz_track_lists: true
|
||||
})
|
||||
);
|
||||
await waitFor(() => expect(lb).not.toBeChecked());
|
||||
expect(mb).toBeChecked();
|
||||
});
|
||||
|
||||
test('a failed save puts the switch back and says so', async () => {
|
||||
vi.mocked(getLookupSettings).mockResolvedValue(bothOn);
|
||||
vi.mocked(updateLookupSettings).mockRejectedValue(new Error('offline'));
|
||||
render(LookupSettingsCard);
|
||||
|
||||
const mb = await screen.findByRole('switch', { name: /musicbrainz track lists/i });
|
||||
await fireEvent.click(mb);
|
||||
await waitFor(() => expect(pushToast).toHaveBeenCalled());
|
||||
expect(mb).toBeChecked();
|
||||
});
|
||||
});
|
||||
@@ -12,11 +12,12 @@
|
||||
import { qk } from '#lib/api/queries.js';
|
||||
import AcoustIDCard from '#lib/components/AcoustIDCard.svelte';
|
||||
import ProviderGroup from '#lib/components/admin/ProviderGroup.svelte';
|
||||
import LookupSettingsCard from '#lib/components/admin/LookupSettingsCard.svelte';
|
||||
import SettingsColumns from '#lib/components/settings/SettingsColumns.svelte';
|
||||
|
||||
// Admin › Metadata sources: the outside sources Minstrel asks
|
||||
// about your music. AcoustID names a recording from its sound; the cover
|
||||
// art and tag sources share one block.
|
||||
// art and tag sources share one block; the other lookups have a switch each.
|
||||
|
||||
const client = useQueryClient();
|
||||
const coverStore = createCoverProvidersQuery();
|
||||
@@ -88,5 +89,6 @@
|
||||
keyPlaceholder="Paste a key to use this source"
|
||||
note={tagNote}
|
||||
/>
|
||||
<LookupSettingsCard />
|
||||
{/snippet}
|
||||
</SettingsColumns>
|
||||
|
||||
@@ -20,7 +20,10 @@ vi.mock('#lib/api/admin.js', () => ({
|
||||
getAcoustID: vi.fn(() => new Promise(() => {})),
|
||||
updateAcoustIDSettings: vi.fn(),
|
||||
runAcoustIDLookup: vi.fn(),
|
||||
listUnsettledAcoustID: vi.fn()
|
||||
listUnsettledAcoustID: vi.fn(),
|
||||
// LookupSettingsCard loads on mount and has its own suite; left pending.
|
||||
getLookupSettings: vi.fn(() => new Promise(() => {})),
|
||||
updateLookupSettings: vi.fn()
|
||||
}));
|
||||
|
||||
import MetadataPage from './+page.svelte';
|
||||
|
||||
Reference in New Issue
Block a user