Skip to content

Commit

Permalink
removed getPlaylistItems
Browse files Browse the repository at this point in the history
  • Loading branch information
synan798 committed Dec 22, 2024
1 parent 292c5db commit 6914cc0
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions composables/useSpotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export default function useSpotify(playlistId: string) {
const data = await res.json();

for (const item of data.items) {
const itemCount = await getPlaylistItems(item.id);
const itemCount = item.tracks.total
console.log(itemCount)
if (itemCount >= 8) {
const exists = userPlaylists.value.some(playlist => playlist.id === item.id);
if (!exists) {
Expand All @@ -117,29 +118,6 @@ export default function useSpotify(playlistId: string) {
}
}

async function getPlaylistItems(playlistId: string): Promise<number> {
try {
const res = await fetch(`https://api.spotify.com/v1/playlists/${ playlistId }/tracks`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token.value}`,
},
});

if (!res.ok) {
console.error(`Error: ${res.status} - ${res.statusText}`);
return 0;
}

const data = await res.json();

return data.items.length;
} catch (error) {
console.error('Failed to get playlists:', error);
return 0;
}
}

async function getTrackCover(trackId: string): Promise<string> {
try {
const res = await fetch(`https://api.spotify.com/v1/tracks/${trackId}`, {
Expand Down Expand Up @@ -169,7 +147,6 @@ export default function useSpotify(playlistId: string) {
followPlaylist,
unfollowPlaylist,
getUserPlaylists,
getPlaylistItems,
getTrackCover
};
}

0 comments on commit 6914cc0

Please sign in to comment.