Files
psysonic/src/store/promoteStreamCache.ts
T
cucadmuh 45e0e1206f fix(playback): pin queue playback to source server when browsing another library (#717)
* fix(playback): pin queue streams, cover art, and library links to queue server

When the active server changes while a queue from another server is playing,
keep streams and UI on queueServerId; switch back for artist/album links and
queue or player-bar context menus.

* fix(playback): switch to queue server when opening Now Playing

Ensure active server matches queueServerId before Subsonic fetches on the
Now Playing page, mobile player route, and queue info panel; scope caches
by server id.

* docs(credits): mention Now Playing in PR #717 contribution line

* fix(playback): route scrobble and queue sync to queue server

Address PR review: apiForServer for scrobble/now-playing/savePlayQueue,
clear queueServerId on server removal, mini-player queueServerId sync,
block cross-server enqueue with toast, and regression tests.
2026-05-15 16:08:41 +03:00

39 lines
1.4 KiB
TypeScript

import { buildStreamUrlForServer } 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: buildStreamUrlForServer(serverId, 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
}
}