mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
feat(server): capability framework, AudioMuse sonic routing & PsyLab Connections (#1033)
* feat(server): probe AudioMuse via OpenSubsonic and add PsyLab Connections tab Navidrome ≥0.62: detect sonicSimilarity extension for reliable plugin signal; older servers keep the legacy getSimilarSongs probe. PsyLab gets a Connections tab with session, endpoint, and active-server capability details. * feat(psylab): polish Connections tab, admin role probe, and tab bar layout Status badges and Navidrome admin/user validation in Connections; prevent PsyLab tab row from vertically collapsing under the Logs flex layout. * docs: add CHANGELOG and credits for PR #1032 * feat(settings): auto-enable AudioMuse on Navidrome 0.62+ with status indicator Replace the per-server manual toggle with a probe-driven badge when sonicSimilarity is available; pre-0.62 Navidrome keeps the legacy toggle. * feat(server): capability framework with AudioMuse sonic routing Add a declarative server-capability catalog (src/serverCapabilities/) that picks a feature strategy per server generation, runs only the needed probes, and routes API calls. AudioMuse Instant Mix now prefers the OpenSubsonic sonicSimilarity endpoint (getSonicSimilarTracks) on Navidrome 0.62+ and falls back to legacy getSimilarSongs. - catalog/context/resolve: eligibility, detection, activation, call routing - storeView: read facade over the existing per-server probe maps - getSonicSimilarTracks API client + fetchSimilarTracksRouted router - route Instant Mix and Lucky Mix through the resolver - ServersTab + PsyLab Connections read the resolver (auto status vs toggle) - tests: resolve, storeView, router * docs: update CHANGELOG and credits for PR #1033 Renamed branch supersedes PR #1032: point changelog/credits at #1033 and document the server-capability framework, auto-managed AudioMuse indicator, and sonic Instant Mix routing. * refactor(server): address PR #1033 review — idempotent probe, drop dead code - Make scheduleInstantMixProbeForServer idempotent: skip when a definitive result is cached; re-probe only on force (add/edit/test server), a prior error, or a server version/type change (invalidated in setSubsonicServerIdentity). Removes the steady-state 120 s re-probe, the present→probing→present flicker, and the momentary legacy-fallback routing window. - Remove now-dead identity helpers (showAudiomuseNavidromeServerSetting, isAudiomusePluginAutoManaged, isNavidromeSonicSimilarityEligible, resolveAudiomusePluginProbeUiStatus + type) and the superseded probeAudiomusePluginWithCredentials; the catalog is the single source of truth. - Drop the never-emitted 'unsupported' AudiomusePluginProbeResult variant. - Fill audiomuseStatus* keys in all 8 non-en locales. - Tests: probe idempotency + version-change invalidation; retarget OpenSubsonic test to fetchOpenSubsonicExtensionsWithCredentials.
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { renderHook, waitFor } from '@testing-library/react';
|
||||
import { resetAuthStore } from '@/test/helpers/storeReset';
|
||||
import { useAuthStore } from '@/store/authStore';
|
||||
|
||||
vi.mock('@/api/navidromeAdmin', () => ({
|
||||
ndLogin: vi.fn(),
|
||||
}));
|
||||
|
||||
import { ndLogin } from '@/api/navidromeAdmin';
|
||||
import { useNavidromeAdminRole } from './useNavidromeAdminRole';
|
||||
|
||||
beforeEach(() => {
|
||||
resetAuthStore();
|
||||
vi.mocked(ndLogin).mockReset();
|
||||
});
|
||||
|
||||
function seedNavidromeServer(): string {
|
||||
const id = useAuthStore.getState().addServer({
|
||||
name: 'Home',
|
||||
url: 'music.example.com',
|
||||
username: 'tester',
|
||||
password: 'pw',
|
||||
});
|
||||
useAuthStore.getState().setActiveServer(id);
|
||||
useAuthStore.getState().setLoggedIn(true);
|
||||
useAuthStore.getState().setSubsonicServerIdentity(id, {
|
||||
type: 'navidrome',
|
||||
serverVersion: '0.62.0',
|
||||
openSubsonic: true,
|
||||
});
|
||||
return id;
|
||||
}
|
||||
|
||||
describe('useNavidromeAdminRole', () => {
|
||||
it('returns na when not logged in', () => {
|
||||
const id = useAuthStore.getState().addServer({
|
||||
name: 'Home',
|
||||
url: 'https://music.example.com',
|
||||
username: 'tester',
|
||||
password: 'pw',
|
||||
});
|
||||
useAuthStore.getState().setActiveServer(id);
|
||||
useAuthStore.getState().setSubsonicServerIdentity(id, {
|
||||
type: 'navidrome',
|
||||
serverVersion: '0.62.0',
|
||||
openSubsonic: true,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useNavidromeAdminRole());
|
||||
expect(result.current).toBe('na');
|
||||
expect(ndLogin).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns checking until server identity is known', () => {
|
||||
const id = useAuthStore.getState().addServer({
|
||||
name: 'Home',
|
||||
url: 'https://music.example.com',
|
||||
username: 'tester',
|
||||
password: 'pw',
|
||||
});
|
||||
useAuthStore.getState().setActiveServer(id);
|
||||
useAuthStore.getState().setLoggedIn(true);
|
||||
|
||||
const { result } = renderHook(() => useNavidromeAdminRole());
|
||||
expect(result.current).toBe('checking');
|
||||
expect(ndLogin).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns na for non-Navidrome servers', () => {
|
||||
const id = useAuthStore.getState().addServer({
|
||||
name: 'Ampache',
|
||||
url: 'https://music.example.com',
|
||||
username: 'tester',
|
||||
password: 'pw',
|
||||
});
|
||||
useAuthStore.getState().setActiveServer(id);
|
||||
useAuthStore.getState().setLoggedIn(true);
|
||||
useAuthStore.getState().setSubsonicServerIdentity(id, {
|
||||
type: 'ampache',
|
||||
serverVersion: '6.0.0',
|
||||
openSubsonic: false,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useNavidromeAdminRole());
|
||||
expect(result.current).toBe('na');
|
||||
expect(ndLogin).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('probes Navidrome native login and reports admin', async () => {
|
||||
seedNavidromeServer();
|
||||
vi.mocked(ndLogin).mockResolvedValue({ token: 't', userId: '1', isAdmin: true });
|
||||
|
||||
const { result } = renderHook(() => useNavidromeAdminRole());
|
||||
await waitFor(() => expect(result.current).toBe('admin'));
|
||||
expect(ndLogin).toHaveBeenCalledWith('http://music.example.com', 'tester', 'pw');
|
||||
});
|
||||
|
||||
it('probes Navidrome native login and reports standard user', async () => {
|
||||
seedNavidromeServer();
|
||||
vi.mocked(ndLogin).mockResolvedValue({ token: 't', userId: '2', isAdmin: false });
|
||||
|
||||
const { result } = renderHook(() => useNavidromeAdminRole());
|
||||
await waitFor(() => expect(result.current).toBe('user'));
|
||||
});
|
||||
|
||||
it('returns error when native login fails', async () => {
|
||||
seedNavidromeServer();
|
||||
vi.mocked(ndLogin).mockRejectedValue(new Error('denied'));
|
||||
|
||||
const { result } = renderHook(() => useNavidromeAdminRole());
|
||||
await waitFor(() => expect(result.current).toBe('error'));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { ndLogin } from '../api/navidromeAdmin';
|
||||
import { useAuthStore } from '../store/authStore';
|
||||
import { isNavidromeServer } from '../utils/server/subsonicServerIdentity';
|
||||
|
||||
export type NavidromeAdminRole = 'idle' | 'checking' | 'admin' | 'user' | 'na' | 'error';
|
||||
|
||||
function normalizeServerUrl(url: string): string {
|
||||
const withScheme = url.startsWith('http') ? url : `http://${url}`;
|
||||
return withScheme.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Probes Navidrome native login for the active server to learn whether the
|
||||
* current Subsonic credentials belong to an admin account.
|
||||
*/
|
||||
export function useNavidromeAdminRole(): NavidromeAdminRole {
|
||||
const isLoggedIn = useAuthStore(s => s.isLoggedIn);
|
||||
const activeServerId = useAuthStore(s => s.activeServerId);
|
||||
const server = useAuthStore(s => s.servers.find(srv => srv.id === s.activeServerId));
|
||||
const identity = useAuthStore(s =>
|
||||
activeServerId ? s.subsonicServerIdentityByServer[activeServerId] : undefined,
|
||||
);
|
||||
const [role, setRole] = useState<NavidromeAdminRole>('idle');
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn || !server) {
|
||||
setRole('na');
|
||||
return;
|
||||
}
|
||||
if (!identity) {
|
||||
setRole('checking');
|
||||
return;
|
||||
}
|
||||
if (!isNavidromeServer(identity)) {
|
||||
setRole('na');
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
setRole('checking');
|
||||
const serverUrl = normalizeServerUrl(server.url);
|
||||
ndLogin(serverUrl, server.username, server.password)
|
||||
.then(res => {
|
||||
if (cancelled) return;
|
||||
setRole(res.isAdmin ? 'admin' : 'user');
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setRole('error');
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [
|
||||
isLoggedIn,
|
||||
activeServerId,
|
||||
server?.id,
|
||||
server?.url,
|
||||
server?.username,
|
||||
server?.password,
|
||||
identity?.type,
|
||||
identity?.serverVersion,
|
||||
]);
|
||||
|
||||
return role;
|
||||
}
|
||||
Reference in New Issue
Block a user