diff --git a/pages/api/Spotify.js b/pages/api/Spotify.js deleted file mode 100644 index 65ee76d..0000000 --- a/pages/api/Spotify.js +++ /dev/null @@ -1,60 +0,0 @@ -import querystring from 'querystring'; - -const { - SPOTIFY_CLIENT_ID: client_id, - SPOTIFY_CLIENT_SECRET: client_secret, - SPOTIFY_REFRESH_TOKEN: refresh_token, -} = process.env; - -const basic = Buffer.from(`${client_id}:${client_secret}`).toString('base64'); -const NOW_PLAYING_ENDPOINT = `https://api.spotify.com/v1/me/player/currently-playing`; -const TOKEN_ENDPOINT = `https://accounts.spotify.com/api/token`; - -const getAccessToken = async () => { - const response = await fetch(TOKEN_ENDPOINT, { - method: 'POST', - headers: { - Authorization: `Basic ${basic}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - body: querystring.stringify({ - grant_type: 'refresh_token', - refresh_token, - }), - }); - - return response.json(); -}; - -export const getNowPlaying = async () => { - const { access_token } = await getAccessToken(); - - return fetch(NOW_PLAYING_ENDPOINT, { - headers: { - Authorization: `Bearer ${access_token}`, - }, - }); -}; - -const Spotify = async (_, res) => { - const response = await getNowPlaying(); - - if (response.status === 204 || response.status > 400) { - return res.status(200).json({ isPlaying: false }); - } - - const song = await response.json(); - const isPlaying = song.is_playing; - const title = song.item.name; - const artist = song.item.artists.map((_artist) => _artist.name).join(', '); - const album = song.item.album.name; - - return res.status(200).json({ - album, - artist, - isPlaying, - title, - }); -}; - -export default Spotify \ No newline at end of file diff --git a/pages/components/Profile/Spotify.js b/pages/components/Profile/Spotify.js index 3fb4865..76ff401 100644 --- a/pages/components/Profile/Spotify.js +++ b/pages/components/Profile/Spotify.js @@ -11,7 +11,7 @@ function App () { useEffect(() => { const fetchData = async () => { const result = await axios( - '/api/Spotify', + 'https://vercel-spotify-api.vercel.app/api/Spotify', ); setData(result.data); }; diff --git a/pages/profile.js b/pages/profile.js index 778c708..165e5ad 100644 --- a/pages/profile.js +++ b/pages/profile.js @@ -25,8 +25,6 @@ import PublicKeys from './components/Profile/PublicKeys' import Button from './components/Profile/Button' import Contact from './components/Profile/Contact' import NintendoSW from "./components/Profile/NintendoSW" -import FitbitSleep from "./components/Fitbit/Sleep" -import FitbitHeartrate from "./components/Fitbit/Heartrate" // next-seo import { NextSeo } from 'next-seo'; @@ -63,8 +61,6 @@ export default function Profile(props) {
- {/* - */}