Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 35 36 37 38 | 44x 2x | import { getUserPlaylists } from "utils/spotifyCalls"; export async function getAllMyPlaylists(): Promise<SpotifyApi.ListOfCurrentUsersPlaylistsResponse | null> { const limit = 50; const playlistsData = await getUserPlaylists(0, 50); let restPlaylistsData: | SpotifyApi.ListOfCurrentUsersPlaylistsResponse | undefined; Iif (!playlistsData) return null; const max = Math.ceil(playlistsData.total / limit); Iif (max <= 1) { return playlistsData; } for (let i = 1; i < max; i++) { const resPlaylistsData = await getUserPlaylists(limit * i, 50); if (restPlaylistsData && resPlaylistsData) { restPlaylistsData = { ...restPlaylistsData, items: [...restPlaylistsData.items, ...resPlaylistsData.items], }; } else Iif (resPlaylistsData) { restPlaylistsData = resPlaylistsData; } } Iif (!restPlaylistsData) { return playlistsData; } const allPlaylists = { ...playlistsData, items: [...playlistsData.items, ...restPlaylistsData.items], }; return allPlaylists; } |