/** * Queue a server-only item for download on the next reconnect. * * Offline this only persists a `pending` downloads row with no `stream_url`; * the reconnect handler resolves the URL and the pump starts it (see * `offlineCatalog`). Shared by the grid card and the list row so the two * surfaces queue identically — the list view previously had no way to queue at * all. * * TRACES: UR-052 | DR-292 */ import type { MediaItem } from "$lib/api/types"; import { downloads } from "$lib/stores/downloads"; import { auth } from "$lib/stores/auth"; export async function queueOfflineDownload(item: MediaItem): Promise { const userId = auth.getUserId(); if (!userId) throw new Error("Not signed in"); // A sensible on-disk path; the backend heals `stream_url` on reconnect. const filePath = `downloads/${item.id}`; await downloads.downloadItem( item.id, userId, filePath, undefined, undefined, item.name, item.artists?.join(", ") ?? undefined, item.albumName ?? undefined, ); }