1
0
Fork 0
mirror of https://github.com/skidoodle/albert.lol.git synced 2025-02-15 06:09:15 +01:00
albert.lol/pages/api/spotify.ts
skidoodle 7412a499ed
Update spotify.ts
Signed-off-by: skidoodle <53189968+skidoodle@users.noreply.github.com>
2022-10-25 14:31:14 +02:00

23 lines
688 B
TypeScript

import { NextApiRequest, NextApiResponse } from 'next';
import { SpotifyService } from 'spotify-now-playing'
export default async function (req: NextApiRequest, res: NextApiResponse) {
const { CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN } = process.env;
const spotify = new SpotifyService(CLIENT_ID!, CLIENT_SECRET!, REFRESH_TOKEN!)
const song = await spotify.getCurrentSong()
if(!!song|| !song.isPlaying ) {
return res.status(200).json({
nowplaying: false,
});
}
res.status(200).json({
nowplaying: true,
song: {
artist: song.artist.name,
title: song.title,
url: song.externalUrl,
}
});
}