add clunky fuckass fix for malformed track response
This commit is contained in:
parent
c63d82c95f
commit
131e834d52
1 changed files with 25 additions and 1 deletions
26
js/api.js
26
js/api.js
|
|
@ -401,13 +401,37 @@ export class LosslessAPI {
|
||||||
return result;
|
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') {
|
async getTrack(id, quality = 'LOSSLESS') {
|
||||||
const cacheKey = `${id}_${quality}`;
|
const cacheKey = `${id}_${quality}`;
|
||||||
const cached = await this.cache.get('track', cacheKey);
|
const cached = await this.cache.get('track', cacheKey);
|
||||||
if (cached) return cached;
|
if (cached) return cached;
|
||||||
|
|
||||||
const response = await this.fetchWithRetry(`/track/?id=${id}&quality=${quality}`);
|
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);
|
await this.cache.set('track', cacheKey, result);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue