Converted spotify.js to TypeScript

This commit is contained in:
r-freeman 2023-01-14 23:52:36 +00:00
parent 78004ff62b
commit 3062b933c7

View File

@ -9,6 +9,14 @@ const SPOTIFY_RECENTLY_PLAYED = "https://api.spotify.com/v1/me/player/recently-p
const basic = Buffer.from(`${SPOTIFY_CLIENT_ID}:${SPOTIFY_CLIENT_SECRET}`).toString('base64') const basic = Buffer.from(`${SPOTIFY_CLIENT_ID}:${SPOTIFY_CLIENT_SECRET}`).toString('base64')
type Response = {
access_token: string
token_type: string
scope: string
expires_in: number
refresh_token: string
}
const getAccessToken = async () => { const getAccessToken = async () => {
const response = await fetch(SPOTIFY_TOKEN, { const response = await fetch(SPOTIFY_TOKEN, {
method: 'POST', method: 'POST',
@ -26,7 +34,7 @@ const getAccessToken = async () => {
} }
export const getCurrentlyPlaying = async () => { export const getCurrentlyPlaying = async () => {
const {access_token} = await getAccessToken() const {access_token}: Response = await getAccessToken() as Response
return await fetch(SPOTIFY_CURRENTLY_PLAYING, { return await fetch(SPOTIFY_CURRENTLY_PLAYING, {
headers: { headers: {
@ -35,8 +43,9 @@ export const getCurrentlyPlaying = async () => {
}) })
} }
export const getRecentlyPlayed = async () => { export const getRecentlyPlayed = async () => {
const {access_token} = await getAccessToken() const {access_token}: Response = await getAccessToken() as Response
return await fetch(SPOTIFY_RECENTLY_PLAYED, { return await fetch(SPOTIFY_RECENTLY_PLAYED, {
headers: { headers: {