From 3062b933c745c5564b63b7b551ca52080828bbb4 Mon Sep 17 00:00:00 2001 From: r-freeman Date: Sat, 14 Jan 2023 23:52:36 +0000 Subject: [PATCH] Converted spotify.js to TypeScript --- src/lib/{spotify.js => spotify.ts} | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) rename src/lib/{spotify.js => spotify.ts} (82%) diff --git a/src/lib/spotify.js b/src/lib/spotify.ts similarity index 82% rename from src/lib/spotify.js rename to src/lib/spotify.ts index e428a83..dbaa9b1 100644 --- a/src/lib/spotify.js +++ b/src/lib/spotify.ts @@ -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') +type Response = { + access_token: string + token_type: string + scope: string + expires_in: number + refresh_token: string +} + const getAccessToken = async () => { const response = await fetch(SPOTIFY_TOKEN, { method: 'POST', @@ -26,7 +34,7 @@ const getAccessToken = async () => { } export const getCurrentlyPlaying = async () => { - const {access_token} = await getAccessToken() + const {access_token}: Response = await getAccessToken() as Response return await fetch(SPOTIFY_CURRENTLY_PLAYING, { headers: { @@ -35,8 +43,9 @@ export const getCurrentlyPlaying = async () => { }) } + export const getRecentlyPlayed = async () => { - const {access_token} = await getAccessToken() + const {access_token}: Response = await getAccessToken() as Response return await fetch(SPOTIFY_RECENTLY_PLAYED, { headers: {