1- const createSpotifyApi = require ( '../utils/spotifyApi' ) ;
1+ const spotifyApi = require ( '../utils/spotifyApi' ) ;
22
33const path = require ( 'path' ) ;
44const playlistImages = [
@@ -18,18 +18,16 @@ const convertImageToBase64 = async (imagePath) => {
1818
1919const getAuthUrl = ( ) => {
2020 const scopes = [ 'user-library-read' , 'playlist-modify-private' , 'playlist-modify-public' ] ;
21- return createSpotifyApi . createAuthorizeURL ( scopes , 'state-key' ) ;
21+ return spotifyApi . createAuthorizeURL ( scopes , 'state-key' ) ;
2222} ;
2323
2424const setAccessToken = ( accessToken ) => {
25- createSpotifyApi . setAccessToken ( accessToken ) ;
25+ spotifyApi . setAccessToken ( accessToken ) ;
2626} ;
2727
28- const getUserPlaylists = async ( token , offset = 0 ) => {
29- const spotifyApi = createSpotifyApi ( ) ;
30- spotifyApi . setAccessToken ( token ) ;
31-
28+ const getUserPlaylists = async ( offset = 0 ) => {
3229 const playlistResponse = await spotifyApi . getUserPlaylists ( { offset } ) ;
30+
3331 const likedSongsResponse = await spotifyApi . getMySavedTracks ( ) ;
3432
3533 return {
@@ -40,7 +38,7 @@ const getUserPlaylists = async (token, offset = 0) => {
4038
4139const getLikedSongs = async ( ) => {
4240 try {
43- const response = await createSpotifyApi . getMySavedTracks ( {
41+ const response = await spotifyApi . getMySavedTracks ( {
4442 limit : 50 ,
4543 offset : 0
4644 } ) ;
@@ -56,19 +54,19 @@ const getLikedSongs = async () => {
5654
5755
5856const getPlaylist = async ( playlistId ) => {
59- const response = await createSpotifyApi . getPlaylist ( playlistId ) ;
57+ const response = await spotifyApi . getPlaylist ( playlistId ) ;
6058 return response . body ;
6159} ;
6260
6361const getPlaylistTracks = async ( playlistId ) => {
64- const response = await createSpotifyApi . getPlaylistTracks ( playlistId ) ;
62+ const response = await spotifyApi . getPlaylistTracks ( playlistId ) ;
6563 return response . body ;
6664} ;
6765
6866const getTrackRecommendations = async ( seedTrackId ) => {
69- const seedTrackFeatures = await createSpotifyApi . getAudioFeaturesForTrack ( seedTrackId ) ;
67+ const seedTrackFeatures = await spotifyApi . getAudioFeaturesForTrack ( seedTrackId ) ;
7068
71- const response = await createSpotifyApi . getRecommendations ( {
69+ const response = await spotifyApi . getRecommendations ( {
7270 seed_tracks : [ seedTrackId ] ,
7371 limit : 100 ,
7472 target_instrumentalness : seedTrackFeatures . body . instrumentalness ,
@@ -102,25 +100,25 @@ const getTrackRecommendations = async (seedTrackId) => {
102100} ;
103101
104102const createPlaylist = async ( userId , name , description , trackUris ) => {
105- const playlistResponse = await createSpotifyApi . createPlaylist ( userId , {
103+ const playlistResponse = await spotifyApi . createPlaylist ( userId , {
106104 name,
107105 description,
108106 } ) ;
109107
110108 const playlistId = playlistResponse . body . id ;
111- await createSpotifyApi . addTracksToPlaylist ( playlistId , trackUris ) ;
109+ await spotifyApi . addTracksToPlaylist ( playlistId , trackUris ) ;
112110
113111 const randomImageIndex = Math . floor ( Math . random ( ) * playlistImages . length ) ;
114112 const imagePath = playlistImages [ randomImageIndex ] ;
115113
116114 const imageData = await convertImageToBase64 ( imagePath ) ;
117- await createSpotifyApi . uploadCustomPlaylistCoverImage ( playlistId , imageData ) ;
115+ await spotifyApi . uploadCustomPlaylistCoverImage ( playlistId , imageData ) ;
118116
119117 return playlistId ;
120118} ;
121119
122120const createPlaylistFromSeedTrack = async ( userId , seedTrackId ) => {
123- const seedTrack = await createSpotifyApi . getTrack ( seedTrackId ) ;
121+ const seedTrack = await spotifyApi . getTrack ( seedTrackId ) ;
124122 const seedTrackName = seedTrack . body . name ;
125123
126124 const recommendations = await getTrackRecommendations ( seedTrackId ) ;
0 commit comments