Skip to content

Commit

Permalink
changed itemCount of playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
synan798 committed Dec 22, 2024
1 parent bfb3bdc commit 4ae8aef
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 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,28 +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 {
Expand Down Expand Up @@ -169,7 +148,6 @@ export default function useSpotify(playlistId: string) {
followPlaylist,
unfollowPlaylist,
getUserPlaylists,
getPlaylistItems,
getTrackCover
};
}

0 comments on commit 4ae8aef

Please sign in to comment.