fix(netease): load playlists beyond 1000 tracks

This commit is contained in:
yhxglsa2016 committed 2026-11-28 09:49:35 +08:00
1 parent fc4d472685
commit 0b3bb0c3dd
3 files changed
+69 -4

No files matched your search

+45
View File
@@ -237,6 +237,51 @@ describe("NeteaseProvider.search pagination", () => {
});
});
describe("NeteaseProvider.getPlaylistSongs (#200)", () => {
function playlistFixture(size: number) {
const ids = Array.from({ length: size }, (_, i) => i + 1);
const get = vi.fn().mockResolvedValue({
data: { playlist: { trackIds: ids.map(id => ({ id })) } },
});
const post = vi.fn(async (_path: string, body: { ids: string }) => ({
data: { songs: body.ids.split(",").reverse().map(id => ({ id: Number(id) })) },
}));
const provider = new NeteaseProvider("http://x");
provider.setCookie("MUSIC_U=test");
(provider as any).api = { get, post };
return { provider, ids, get, post };
}
it.each([0, 12, 1000, 1360, 2000])("loads %i tracks in playlist order", async size => {
const { provider, ids, get, post } = playlistFixture(size);
const songs = await provider.getPlaylistSongs("920292129");
expect(songs.map(song => song.id)).toEqual(ids.map(String));
expect(get.mock.calls).toEqual([["/playlist/detail", {
params: { id: "920292129", cookie: "MUSIC_U=test" },
}]]);
expect(post).toHaveBeenCalledTimes(Math.ceil(size / 1000));
for (let offset = 0; offset < size; offset += 1000) {
expect(post).toHaveBeenNthCalledWith(offset / 1000 + 1, "/song/detail", {
ids: ids.slice(offset, offset + 1000).join(","), cookie: "MUSIC_U=test",
}, { headers: { "x-apicache-bypass": "1" } });
}
});
it("continues past unavailable tracks in an earlier batch", async () => {
const { provider, post } = playlistFixture(1002);
post.mockResolvedValueOnce({ data: { songs: [{ id: 1 }] } });
const songs = await provider.getPlaylistSongs("920292129");
expect(songs.map(song => song.id)).toEqual(["1", "1001", "1002"]);
});
it("propagates a failed batch instead of returning a partial playlist", async () => {
const { provider, post } = playlistFixture(1360);
post.mockResolvedValueOnce({ data: { songs: [{ id: 1 }] } })
.mockRejectedValueOnce(new Error("sidecar unavailable"));
await expect(provider.getPlaylistSongs("920292129")).rejects.toThrow("sidecar unavailable");
});
});
describe("mapNeteaseArtists (artist search + detail)", () => {
it("maps cloudsearch type=100 artist entries", () => {
const out = mapNeteaseArtists([