mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-22 12:10:11 +09:00
Cleanup
This commit is contained in:
parent
49bd87b276
commit
8513ee795f
@ -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
|
|
@ -11,7 +11,7 @@ function App () {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
const result = await axios(
|
const result = await axios(
|
||||||
'/api/Spotify',
|
'https://vercel-spotify-api.vercel.app/api/Spotify',
|
||||||
);
|
);
|
||||||
setData(result.data);
|
setData(result.data);
|
||||||
};
|
};
|
||||||
|
@ -25,8 +25,6 @@ import PublicKeys from './components/Profile/PublicKeys'
|
|||||||
import Button from './components/Profile/Button'
|
import Button from './components/Profile/Button'
|
||||||
import Contact from './components/Profile/Contact'
|
import Contact from './components/Profile/Contact'
|
||||||
import NintendoSW from "./components/Profile/NintendoSW"
|
import NintendoSW from "./components/Profile/NintendoSW"
|
||||||
import FitbitSleep from "./components/Fitbit/Sleep"
|
|
||||||
import FitbitHeartrate from "./components/Fitbit/Heartrate"
|
|
||||||
|
|
||||||
// next-seo
|
// next-seo
|
||||||
import { NextSeo } from 'next-seo';
|
import { NextSeo } from 'next-seo';
|
||||||
@ -63,8 +61,6 @@ export default function Profile(props) {
|
|||||||
<div>
|
<div>
|
||||||
<DiscordPlaying />
|
<DiscordPlaying />
|
||||||
<Spotify />
|
<Spotify />
|
||||||
{/* <FitbitSleep />
|
|
||||||
<FitbitHeartrate /> */}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user