Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/lib/me/MeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Markets,
LibraryTrack
} from '../../interfaces/Spotify';
import { chunk } from '../../util/chunk';

import { Manager } from '../Manager';

Expand Down Expand Up @@ -142,19 +143,25 @@ export class MeManager extends Manager {
* @param {string} ids Array of IDs.
*/
async saveTracks(ids: string[]): Promise<void> {
await this.http.put(`/v1/me/tracks`, {
ids
});
// Use an async loop to preserve the order of saves
for (const chunkIds of chunk(ids, 50)) {
await this.http.put(`/v1/me/tracks`, {
ids: chunkIds
});
}
}

/**
* @description Remove multiple saved tracks by ID. (required scropes: user-library-read).
* @param {string} ids Array of IDs.
*/
async unsaveTracks(ids: string[]): Promise<void> {
await this.http.delete(`/v1/me/tracks`, {
query: { ids: ids.join(',') }
});
// Use an async loop to preserve the order of unsaves
for (const chunkIds of chunk(ids, 50)) {
await this.http.delete(`/v1/me/tracks`, {
ids: chunkIds
});
}
}

async playlists(options?: {
Expand Down