@@ -120,13 +120,27 @@ export const getUserLikedArtists = async (
120
120
return data . artists . items ;
121
121
} ;
122
122
123
+ type LikedSongs = { total : number ; items : Track [ ] } ;
124
+
123
125
export const getUserLikedSongs = async (
124
126
session : AuthSession
125
- ) : Promise < { total : number ; items : Track [ ] } > => {
127
+ ) : Promise < LikedSongs > => {
126
128
const data = await customGet (
127
129
`https://api.spotify.com/v1/me/tracks?limit=50` ,
128
130
session
129
131
) ;
132
+
133
+ const finalData = { total : data . total , items : data . items } ;
134
+ let limit = 50 ;
135
+ let currUrl = data . next ;
136
+
137
+ while ( currUrl !== null ) {
138
+ const nextData = await customGet ( currUrl , session ) ;
139
+ finalData . items . push ( ...nextData . items ) ;
140
+ limit += 50 ;
141
+ currUrl = nextData . next ;
142
+ }
143
+
130
144
return {
131
145
total : data . total ,
132
146
items : data . items . map ( ( item : any ) => item . track ) ,
@@ -147,10 +161,23 @@ export const getPlaylistById = async (
147
161
session : AuthSession ,
148
162
playlistId : string
149
163
) : Promise < Playlist > => {
150
- return customGet (
164
+ const data = await customGet (
151
165
`https://api.spotify.com/v1/playlists/${ playlistId } ` ,
152
166
session
153
167
) ;
168
+ const playlist = data ;
169
+
170
+ let limit = 50 ;
171
+ let currUrl = data . tracks . next ;
172
+
173
+ while ( currUrl !== null ) {
174
+ const nextData = await customGet ( currUrl , session ) ;
175
+ playlist . tracks . items . push ( ...nextData . items ) ;
176
+ limit += 50 ;
177
+ currUrl = nextData . next ;
178
+ }
179
+
180
+ return playlist ;
154
181
} ;
155
182
156
183
export const getCategories = async (
0 commit comments