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,3 +1,4 @@
import { getMusicFolders } from '../api/subsonicLibrary';
import React, { Suspense, useCallback, useEffect, useRef, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { invoke } from '@tauri-apps/api/core';
@@ -36,7 +37,7 @@ import { useOrbitStore } from '../store/orbitStore';
import { IS_LINUX, IS_MACOS, IS_WINDOWS } from '../utils/platform';
import { useConnectionStatus } from '../hooks/useConnectionStatus';
import { useAuthStore } from '../store/authStore';
import { getMusicFolders, probeEntityRatingSupport } from '../api/subsonic';
import { probeEntityRatingSupport } from '../api/subsonic';
import { useOfflineStore } from '../store/offlineStore';
import { usePlayerStore } from '../store/playerStore';
import { useThemeStore } from '../store/themeStore';
+3 -5
View File
@@ -1,3 +1,5 @@
import { getSimilarSongs } from '../api/subsonicArtists';
import { getMusicFolders } from '../api/subsonicLibrary';
import { flushPlayQueuePosition } from '../store/queueSync';
import { shuffleArray } from '../utils/shuffleArray';
import { songToTrack } from '../utils/songToTrack';
@@ -11,11 +13,7 @@ import { showToast } from '../utils/toast';
import { endOrbitSession, leaveOrbitSession } from '../utils/orbit';
import { useOrbitStore } from '../store/orbitStore';
import { useAuthStore } from '../store/authStore';
import {
getMusicFolders,
getSimilarSongs,
search as subsonicSearch,
} from '../api/subsonic';
import { search as subsonicSearch } from '../api/subsonic';
import i18n from '../i18n';
import { switchActiveServer } from '../utils/switchActiveServer';
import { usePlayerStore } from '../store/playerStore';