Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/lowmess/stats. Unified 30 day stats API stats.lowmess.com
graphql typescript
Something went wrong. Try again.
12345678910111213141516171819202122232425import fetch from '../lib/fetchWithTimeout'
const getAlbum = async (): Promise<AlbumInfo> => { const uri = `https://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&limit=1&user=${process.env.LASTFM_USERNAME}&period=1month&api_key=${process.env.LASTFM_KEY}&format=json`
const response = await fetch(uri) const data = await response.json()
if (!data.topalbums) { throw new Error(`Last.fm responded without a top albums object`) }
return { name: data.topalbums.album[0].name, artist: data.topalbums.album[0].artist.name, }}
export interface AlbumInfo { readonly name: string readonly artist: string}
export default getAlbum