fix(local-library): use high-positive ids for ephemeral tracks (queue/context u64 compat)
The original design used negative i64 ids to distinguish ephemeral
tracks from DB rows, but the queue and playback-context commands
serialize ids as Vec<u64> end-to-end (V2QueueTrack, v2_set_playback_context).
serde rejects negative numbers at the boundary, so setQueueForLocalTracks
and setPlaybackContext failed the moment the user clicked an ephemeral
track:
invalid value: integer `-1`, expected u64
Switch synthetic ids to a high-positive range (EPHEMERAL_ID_FLOOR =
1<<48) instead. Pros over the negative scheme:
* Valid u64 — passes through the queue/context commands untouched
* Below 2^53 so JS Number round-trips without precision loss
* Far above any realistic DB autoincrement id, so the discrimination
test (`track_id >= EPHEMERAL_ID_FLOOR`) stays unambiguous
Also fixes the snake_case mismatch on EphemeralFolderState — the Rust
struct serializes with its native field names (folder_path,
skipped_files), but the TypeScript type was declared in camelCase, so
ephemeralFolder.folderPath was undefined at render time.
cc
This commit is contained in:
3 files changed
+42
-22
No files matched your search
@@ -839,12 +839,15 @@ pub async fn v2_library_play_track(
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
// Negative ids belong to the ephemeral library (an ad-hoc folder the
|
||||
// user opened without persisting it to local_tracks). Resolve to the
|
||||
// in-memory cache and skip every DB-bound branch below — ephemeral
|
||||
// tracks are never qobuz_download, never offline-cached, never have a
|
||||
// CUE pointer. Just read the file and hand it to the player.
|
||||
if track_id < 0 {
|
||||
// Track ids at or above EPHEMERAL_ID_FLOOR belong to the ephemeral
|
||||
// library (an ad-hoc folder the user opened without persisting it
|
||||
// to local_tracks). Resolve to the in-memory cache and skip every
|
||||
// DB-bound branch below — ephemeral tracks are never qobuz_download,
|
||||
// never offline-cached, never have a CUE pointer. Just read the
|
||||
// file and hand it to the player. The high-positive id range keeps
|
||||
// the existing u64-typed queue/context commands happy while still
|
||||
// being unambiguous (DB autoincrement ids never reach 2^48).
|
||||
if track_id >= crate::ephemeral_library::EPHEMERAL_ID_FLOOR {
|
||||
let track = ephemeral_state
|
||||
.get_track(track_id)
|
||||
.ok_or_else(|| format!("Ephemeral track {} not found (session may have been cleared)", track_id))?;
|
||||
|
||||
Reference in new issue
Block a user