I AM RETARDED

This commit is contained in:
nin0 2025-04-27 08:19:22 -04:00
parent 7021328618
commit 9d674ea262
Signed by: nin0
SSH key fingerprint: SHA256:NOoDnFVvZNFvqfXCIhzr6oCTDImZAbTTuyAysZ8Ufk8

View file

@ -5,25 +5,29 @@ export async function reqSpotify(
method: string = "GET", method: string = "GET",
data?: object data?: object
) { ) {
if (state.explodesAt >= Date.now()) { if (state.explodesAt <= Date.now()) {
console.log("We will be refreshing the token");
const tokenRes = await ( const tokenRes = await (
await fetch("https://accounts.spotify.com/api/token", { await fetch("https://accounts.spotify.com/api/token", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/x-www-form-urlencoded" "Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${Buffer.from(
process.env.CLIENT_ID + ":" + process.env.CLIENT_SECRET
).toString("base64")}`
}, },
body: new URLSearchParams({ body: new URLSearchParams({
refresh_token: state.refreshToken, refresh_token: state.refreshToken,
client_id: process.env.CLIENT_ID!,
grant_type: "refresh_token" grant_type: "refresh_token"
}) })
}) })
).json(); ).json();
console.log(tokenRes);
if (!tokenRes.error) { if (!tokenRes.error) {
state.accessToken = tokenRes.access_token; state.accessToken = tokenRes.access_token;
state.explodesAt = Date.now() + tokenRes.expires_in * 1000; state.explodesAt = Date.now() + tokenRes.expires_in * 1000;
state.refreshToken = tokenRes.refresh_token; state.refreshToken = tokenRes.refresh_token || state.refreshToken;
} }
} }