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).
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { buildStreamUrl } from '../api/subsonicStreamUrl';
|
|
import type { Track } from './playerStoreTypes';
|
|
import { invoke } from '@tauri-apps/api/core';
|
|
import { useHotCacheStore } from './hotCacheStore';
|
|
/**
|
|
* Promote a track whose stream cache is full to the on-disk hot cache.
|
|
* Rust copies the cached bytes into the hot-cache directory and returns
|
|
* the resolved path + size; the JS-side `useHotCacheStore` index gets the
|
|
* entry tagged `'stream-promote'` so the LRU treats it the same as a
|
|
* prefetch hit.
|
|
*
|
|
* Best-effort: any failure is swallowed because the regular hot-cache
|
|
* prefetch path remains a fallback. `customDir` may be null when the user
|
|
* hasn't picked a hot-cache directory yet — Rust then writes to the
|
|
* default location.
|
|
*/
|
|
export async function promoteCompletedStreamToHotCache(
|
|
track: Track,
|
|
serverId: string,
|
|
customDir: string | null,
|
|
): Promise<void> {
|
|
try {
|
|
const res = await invoke<{ path: string; size: number } | null>(
|
|
'promote_stream_cache_to_hot_cache',
|
|
{
|
|
trackId: track.id,
|
|
serverId,
|
|
url: buildStreamUrl(track.id),
|
|
suffix: track.suffix || 'mp3',
|
|
customDir,
|
|
},
|
|
);
|
|
if (!res || !res.path) return;
|
|
useHotCacheStore.getState().setEntry(track.id, serverId, res.path, res.size || 0, 'stream-promote');
|
|
} catch {
|
|
// best-effort promotion; normal hot-cache prefetch remains fallback
|
|
}
|
|
}
|