From 131e834d52dfb2f2cd8230bd6714f2d053c3ae94 Mon Sep 17 00:00:00 2001 From: Samidy Date: Sun, 14 Dec 2025 10:14:13 -0800 Subject: [PATCH] add clunky fuckass fix for malformed track response --- js/api.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/js/api.js b/js/api.js index 2a126c4..bd97bb8 100644 --- a/js/api.js +++ b/js/api.js @@ -401,13 +401,37 @@ export class LosslessAPI { return result; } + + + normalizeTrackResponse(apiResponse) { + if (!apiResponse || typeof apiResponse !== 'object') { + return apiResponse; + } + + // unwrap { version, data } if present + const raw = apiResponse.data ?? apiResponse; + + // fabricate the track object expected by parseTrackLookup + const trackStub = { + duration: raw.duration ?? 0, + id: raw.trackId ?? null + }; + + // return exactly what parseTrackLookup expects + return [trackStub, raw]; +} + + + + async getTrack(id, quality = 'LOSSLESS') { const cacheKey = `${id}_${quality}`; const cached = await this.cache.get('track', cacheKey); if (cached) return cached; const response = await this.fetchWithRetry(`/track/?id=${id}&quality=${quality}`); - const result = this.parseTrackLookup(await response.json()); + const jsonResponse = await response.json(); + const result = this.parseTrackLookup(this.normalizeTrackResponse(jsonResponse)); await this.cache.set('track', cacheKey, result); return result;