This commit is contained in:
skidoodle 2022-08-14 19:59:03 +02:00
parent 3a92d65900
commit 7dedfba1f9
31 changed files with 2971 additions and 1859 deletions

26
pages/api/spotify.ts Normal file
View file

@ -0,0 +1,26 @@
import { NextApiRequest, NextApiResponse } from 'next'
export default async function(req: NextApiRequest, res: NextApiResponse) {
const { LASTFM_USERNAME, LASTFM_API } = process.env
const { recenttracks: response } = await fetch(`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${LASTFM_USERNAME}&api_key=${LASTFM_API}&format=json&limit=1`).then((res) => res.json())
const { track } = response
const { artist, name, url, image } = track[0]
let nowplaying = Boolean(track[0]['@attr']?.nowplaying)
if(nowplaying) {
return res.status(200).json({
nowplaying,
song: {
artist: artist['#text'],
title: name,
url: url,
image: image[2]['#text'],
}
})
}
return res.status(200).json({ nowplaying })
}