// Converts a PlaylistTrack row into the minimal TrackRef shape used // by play queues + track menus. Centralizes the mapping so server // additions (new TrackRef fields) only update one site. // // Returns null when the row cannot be played, for either of the two // reasons a playlist entry can outlive its track: // - track_id is null — the track was removed from the library and only // the playlist's text snapshot remains. // - unavailable — the track is still there, with its history intact, // but its file is missing from disk (#2527). // Callers filter nulls, which is what makes a missing file "get skipped" // everywhere a queue is built rather than at each call site. import type { PlaylistTrack, TrackRef } from '#lib/api/types.js'; export function playlistTrackToRef(row: PlaylistTrack): TrackRef | null { if (!row.track_id || row.unavailable) return null; return { id: row.track_id, title: row.title, album_id: row.album_id ?? '', album_title: row.album_title, artist_id: row.artist_id ?? '', artist_name: row.artist_name, duration_sec: row.duration_sec, stream_url: row.stream_url ?? '' }; }