mirror of
				https://github.com/skidoodle/albert.lol.git
				synced 2025-02-15 06:09:15 +01:00 
			
		
		
		
	init spotify fix
This commit is contained in:
		@@ -21,11 +21,13 @@ export default async function handler(
 | 
				
			|||||||
) {
 | 
					) {
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
    const song = await spotify.getCurrentSong()
 | 
					    const song = await spotify.getCurrentSong()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!song || !song.is_playing) {
 | 
					    if (!song || !song.is_playing) {
 | 
				
			||||||
      return res.status(200).json({
 | 
					      return res.status(200).json({
 | 
				
			||||||
        is_playing: false,
 | 
					        is_playing: false,
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res.status(200).json({
 | 
					    res.status(200).json({
 | 
				
			||||||
      is_playing: true,
 | 
					      is_playing: true,
 | 
				
			||||||
      album: {
 | 
					      album: {
 | 
				
			||||||
@@ -43,8 +45,8 @@ export default async function handler(
 | 
				
			|||||||
      duration: song.duration,
 | 
					      duration: song.duration,
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
  } catch (error) {
 | 
					  } catch (error) {
 | 
				
			||||||
    res
 | 
					    res.status(500).json({
 | 
				
			||||||
      .status(500)
 | 
					      error: 'An error occurred while fetching the song.',
 | 
				
			||||||
      .json({ error: 'An error occurred while fetching the song.' })
 | 
					    })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -42,7 +42,7 @@ export class SpotifyService {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public async getCurrentSong(): Promise<SongResult> {
 | 
					  public async getCurrentSong(): Promise<SongResult | undefined> {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      if (!this.hasAccessToken()) {
 | 
					      if (!this.hasAccessToken()) {
 | 
				
			||||||
        await this.getAccessToken()
 | 
					        await this.getAccessToken()
 | 
				
			||||||
@@ -61,9 +61,8 @@ export class SpotifyService {
 | 
				
			|||||||
      })
 | 
					      })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return SongResultMap.parseSong(response.data)
 | 
					      return SongResultMap.parseSong(response.data)
 | 
				
			||||||
    } catch (error) {
 | 
					    } catch {
 | 
				
			||||||
      await this.getAccessToken()
 | 
					      await this.getAccessToken()
 | 
				
			||||||
      throw error
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user