mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
9606a99efb
Seven domain-eng splits peel ~200 LOC of read endpoints out of `api/subsonic.ts`: - `subsonicStreamUrl.ts` — `buildStreamUrl`, `coverArtCacheKey`, `buildCoverArtUrl`, `buildDownloadUrl` (token-signed URL builders for the four /rest endpoints we hand to the browser). - `subsonicStarRating.ts` — `getStarred`, `star`, `unstar`, `setRating`, `probeEntityRatingSupport`. `setRating` still triggers the lazy `navidromeBrowse` cache invalidation; the same-folder lazy import path is preserved. - `subsonicSearch.ts` — `search`, `searchSongsPaged`. - `subsonicScrobble.ts` — `scrobbleSong`, `reportNowPlaying`, `getNowPlaying`. - `subsonicAlbumInfo.ts` — `getAlbumInfo2`. - `subsonicLyrics.ts` — `getLyricsBySongId`. - `subsonicGenres.ts` — `getGenres`, `getAlbumsByGenre`. 63 external call sites migrated to direct imports. Four `vi.mock` targets in the store-level tests pointed at `../api/subsonic` and were updated to the new module paths. Pure code-move. subsonic.ts: 762 → 561 LOC (−201).
24 lines
911 B
TypeScript
24 lines
911 B
TypeScript
import { api } from './subsonicClient';
|
|
import type { SubsonicStructuredLyrics } from './subsonicTypes';
|
|
|
|
/**
|
|
* Fetches structured lyrics from the server's embedded tags via the
|
|
* OpenSubsonic `getLyricsBySongId` endpoint. Returns null when the
|
|
* server doesn't support the endpoint or the track has no embedded lyrics.
|
|
* Prefers synced lyrics over plain when both are present.
|
|
*/
|
|
export async function getLyricsBySongId(id: string): Promise<SubsonicStructuredLyrics | null> {
|
|
try {
|
|
const data = await api<{ lyricsList: { structuredLyrics?: SubsonicStructuredLyrics[] } }>(
|
|
'getLyricsBySongId.view',
|
|
{ id },
|
|
);
|
|
const list = data.lyricsList?.structuredLyrics;
|
|
if (!list || list.length === 0) return null;
|
|
return list.find(l => l.synced || l.issynced) ?? list[0];
|
|
} catch {
|
|
// Server doesn't support the endpoint or track has no embedded lyrics
|
|
return null;
|
|
}
|
|
}
|