-
Notifications
You must be signed in to change notification settings - Fork 13
/
TrackManager.ts
34 lines (29 loc) · 994 Bytes
/
TrackManager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Track } from '../../interfaces/Spotify';
import { Manager } from '../Manager';
import { chunk } from '../../util';
export class TrackManager extends Manager {
/**
* @description Get a track by ID.
* @param {string} id The ID of the track.
* @returns {Promise<Track>} Returns a promise with a single {@link Track}.
*/
async get(id: string): Promise<Track> {
const res = await this.http.get(`/tracks/${id}`);
return res.data as Track;
}
/**
* @description Get multiple tracks by ID.
* @param {string[]} ids Array of IDs.
* @returns {Promise<Track[]>} Returns a promise with {@link Track}s.
*/
async list(ids: string[]): Promise<Track[]> {
const tracks = await Promise.all(
chunk([...ids], 50).map(async (chunk) => {
const res = await this.http.get('/tracks', { query: { ids: chunk.join(',') } });
const json = res.data;
return json.tracks as Track[];
})
);
return [].concat(...tracks);
}
}