mirror of
https://github.com/skidoodle/albert.lol.git
synced 2026-04-29 11:47:41 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { SpotifyService } from 'spotify-now-playing'
|
||||
|
||||
export default async function Spotify(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.artists.name,
|
||||
title: song.title,
|
||||
url: song.url,
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user