Skip to content

Commit

Permalink
fix: collection order (#569)
Browse files Browse the repository at this point in the history
* fix Apple Music collection order
* rewrite Spotify collection order handling
  • Loading branch information
miraclx authored Sep 6, 2023
1 parent 4840d08 commit 0855665
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/services/apple_music.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ export default class AppleMusic {
uris = (wasArr ? uris : [uris]).flatMap(_uri => {
const parsed = this.parseURI(_uri, store);
if (!parsed) return [];
parsed.value = this.#store.cache.get(parsed.uri);
parsed.result = this.#store.cache.get(parsed.uri);
return [[parsed.id, parsed]];
});
const packs = uris.filter(([, {value}]) => !value).map(([, parsed]) => parsed);
const packs = uris.filter(([, {result}]) => !result).map(([, parsed]) => parsed);
let results = new Map();
for (const [id, {result}] of uris) {
results.set(id, result);
}
uris = Object.fromEntries(uris);
if (packs.length)
(
Expand All @@ -228,9 +232,9 @@ export default class AppleMusic {
)
)
.flat(2)
.forEach(item => (item ? this.#store.cache.set(uris[item.id].uri, (uris[item.id].value = item)) : null));
const ret = Object.values(uris).map(item => item.value);
return !wasArr ? ret[0] : ret;
.forEach(item => (item ? (this.#store.cache.set(uris[item.id].uri, item), results.set(item.id, item)) : null));
results = [...results.values()];
return !wasArr ? results[0] : results;
}

async depaginate(paginatedObject, nextHandler) {
Expand Down
11 changes: 7 additions & 4 deletions src/services/spotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ export default class Spotify {
return [parsedURI.id, this.#store.cache.get(uri)];
});
const ids = uris.filter(([, value]) => !value).map(([id]) => id);
let results = new Map();
for (const [id, result] of uris) {
results.set(id, result);
}
uris = Object.fromEntries(uris);
if (ids.length)
(
Expand All @@ -241,10 +245,9 @@ export default class Spotify {
)
)
.flat(1)
.forEach(item => (!item ? null : (this.#store.cache.set(item.uri, item), (uris[item.id] = item))));

const ret = Object.values(uris);
return !wasArr ? ret[0] : ret;
.forEach(item => (!item ? null : (this.#store.cache.set(item.uri, item), results.set(item.id, item))));
results = [...results.values()];
return !wasArr ? results[0] : results;
}

async getTrack(uris, country) {
Expand Down

0 comments on commit 0855665

Please sign in to comment.