refactor(api): F.49 — extract library + artists + ratings (#614)

Three domain-eng modules peel ~316 LOC of fetch/mapping out of
`api/subsonic.ts`:

- `subsonicLibrary.ts` — browse + random + per-song fetch
  (`getMusicDirectory`, `getMusicIndexes`, `getMusicFolders`,
  `getRandomAlbums`, `getAlbumList`, `getRandomSongs`,
  `getRandomSongsFiltered`, `getSong`, `getAlbum`,
  `filterSongsToActiveLibrary`, `similarSongsRequestCount`, plus
  the private `albumIdsInActiveLibraryScope` cache).
- `subsonicArtists.ts` — artist endpoints (`getArtists`, `getArtist`,
  `getArtistInfo`, `getTopSongs`, `getSimilarSongs2`,
  `getSimilarSongs`). Uses Library's `filterSongsToActiveLibrary` and
  `similarSongsRequestCount` for the per-library scoping fallback.
- `subsonicRatings.ts` — `parseSubsonicEntityStarRating` parser plus
  `prefetchArtistUserRatings` and `prefetchAlbumUserRatings` workers
  with the shared 7-min cache. Calls back into Library/Artists for
  the per-id fetch.

51 external call sites migrated to direct imports. No re-export
shims in `subsonic.ts`. Statistics endpoints still in `subsonic.ts`
keep their `RATING_CACHE_TTL` constant locally (same 7-min window).

subsonic.ts: 1078 → 762 LOC (−316).
This commit is contained in:
Frank Stellmacher
2026-05-13 00:23:53 +02:00
committed by GitHub
parent 72030f17fd
commit 006635de4b
56 changed files with 481 additions and 401 deletions
+2 -1
View File
@@ -1,8 +1,9 @@
import { getArtist } from '../api/subsonicArtists';
import { getAlbum, getSong } from '../api/subsonicLibrary';
import type { SubsonicSong } from '../api/subsonicTypes';
import { songToTrack } from '../utils/songToTrack';
import type { NavigateFunction } from 'react-router-dom';
import type { TFunction } from 'i18next';
import { getAlbum, getArtist, getSong } from '../api/subsonic';
import { useAuthStore } from '../store/authStore';
import { usePlayerStore } from '../store/playerStore';
import { findServerIdForShareUrl, type EntitySharePayloadV1 } from './shareLink';
@@ -6,12 +6,17 @@
* refactor (2026-05-12). This test pins the artist-first / random-fallback
* order, the dedup contract against existingIds, and the autoAdded flag.
*/
import { getSimilarSongs2, getTopSongs } from '../api/subsonicArtists';
import { getRandomSongs } from '../api/subsonicLibrary';
import type { Track } from '../store/playerStoreTypes';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('../api/subsonic', () => ({
vi.mock('../api/subsonicArtists', () => ({
getSimilarSongs2: vi.fn(),
getTopSongs: vi.fn(),
}));
vi.mock('../api/subsonicLibrary', () => ({
getRandomSongs: vi.fn(),
}));
@@ -22,7 +27,6 @@ vi.mock('./mixRatingFilter', () => ({
}));
import { buildInfiniteQueueCandidates } from './buildInfiniteQueueCandidates';
import { getRandomSongs, getSimilarSongs2, getTopSongs } from '../api/subsonic';
import {
enrichSongsForMixRatingFilter,
getMixMinRatingsConfigFromAuth,
+2 -1
View File
@@ -1,5 +1,6 @@
import { getSimilarSongs2, getTopSongs } from '../api/subsonicArtists';
import { getRandomSongs } from '../api/subsonicLibrary';
import type { Track } from '../store/playerStoreTypes';
import { getRandomSongs, getSimilarSongs2, getTopSongs } from '../api/subsonic';
import {
enrichSongsForMixRatingFilter,
getMixMinRatingsConfigFromAuth,
+2 -1
View File
@@ -1,7 +1,8 @@
import { getAlbumList } from '../api/subsonicLibrary';
import type { SubsonicAlbum } from '../api/subsonicTypes';
import { writeFile } from '@tauri-apps/plugin-fs';
import { downloadDir, join } from '@tauri-apps/api/path';
import { getAlbumList, buildCoverArtUrl } from '../api/subsonic';
import { buildCoverArtUrl } from '../api/subsonic';
import { useAuthStore } from '../store/authStore';
// Catppuccin Macchiato palette
const M = {
+2 -1
View File
@@ -1,7 +1,8 @@
import { getSimilarSongs, getTopSongs } from '../api/subsonicArtists';
import { filterSongsToActiveLibrary, getAlbum, getAlbumList, getRandomSongs } from '../api/subsonicLibrary';
import type { SubsonicAlbum, SubsonicSong } from '../api/subsonicTypes';
import type { Track } from '../store/playerStoreTypes';
import { songToTrack } from '../utils/songToTrack';
import { filterSongsToActiveLibrary, getAlbum, getAlbumList, getRandomSongs, getSimilarSongs, getTopSongs } from '../api/subsonic';
import { invoke } from '@tauri-apps/api/core';
import i18n from '../i18n';
import { useAuthStore } from '../store/authStore';
+2 -1
View File
@@ -1,5 +1,6 @@
import { parseSubsonicEntityStarRating, prefetchAlbumUserRatings, prefetchArtistUserRatings } from '../api/subsonicRatings';
import { getRandomSongs } from '../api/subsonicLibrary';
import type { SubsonicAlbum, SubsonicSong } from '../api/subsonicTypes';
import { getRandomSongs, parseSubsonicEntityStarRating, prefetchAlbumUserRatings, prefetchArtistUserRatings } from '../api/subsonic';
import { useAuthStore } from '../store/authStore';
/** Default target list size for Random Mix; per-call override via `fetchRandomMixSongsUntilFull(c, { targetSize })`. */
+2 -9
View File
@@ -1,13 +1,6 @@
import { getSong } from '../api/subsonicLibrary';
import { songToTrack } from '../utils/songToTrack';
import {
createPlaylist,
updatePlaylist,
updatePlaylistMeta,
deletePlaylist,
getPlaylist,
getPlaylists,
getSong,
} from '../api/subsonic';
import { createPlaylist, updatePlaylist, updatePlaylistMeta, deletePlaylist, getPlaylist, getPlaylists } from '../api/subsonic';
import { useAuthStore } from '../store/authStore';
import { useOrbitStore } from '../store/orbitStore';
import { usePlayerStore } from '../store/playerStore';
+1 -1
View File
@@ -1,4 +1,4 @@
import { getAlbum } from '../api/subsonic';
import { getAlbum } from '../api/subsonicLibrary';
import { usePlayerStore } from '../store/playerStore';
import { songToTrack } from './songToTrack';
import { useOrbitStore } from '../store/orbitStore';
+2 -1
View File
@@ -1,6 +1,7 @@
import { getArtist } from '../api/subsonicArtists';
import { getAlbum } from '../api/subsonicLibrary';
import { songToTrack } from '../utils/songToTrack';
import { shuffleArray } from '../utils/shuffleArray';
import { getAlbum, getArtist } from '../api/subsonic';
import { usePlayerStore } from '../store/playerStore';
/**
* All tracks from the artists albums, shuffled — same idea as Artist page “shuffle play”.
+1 -1
View File
@@ -1,5 +1,5 @@
import { getAlbum, getSong } from '../api/subsonicLibrary';
import { songToTrack } from '../utils/songToTrack';
import { getAlbum, getSong } from '../api/subsonic';
import { playAlbum } from './playAlbum';
import { playArtistShuffled } from './playArtistShuffled';
import { usePlayerStore } from '../store/playerStore';