mirror of
https://github.com/neongamerbot-qk/hackclub-nest
synced 2024-11-14 21:19:36 +00:00
enhancement(lint): Fix lint errors for hackclub-spotify-bot/src/spotify.js
Co-authored-by: NeonGamerBot-QK <saahilattud@gmail.com> Signed-off-by: zeon-neon[bot] <136533918+zeon-neon[bot]@users.noreply.github.com>
This commit is contained in:
parent
7499857a57
commit
0bf03719c2
1 changed files with 199 additions and 196 deletions
|
@ -1,4 +1,3 @@
|
|||
|
||||
let token = null;
|
||||
let authStuff = null;
|
||||
const client_id = process.env.SPOTIFY_CLIENT_ID;
|
||||
|
@ -111,18 +110,22 @@ async function fetchWebApi(endpoint, method, body) {
|
|||
}
|
||||
}
|
||||
function saveCredentials(creds) {
|
||||
require('fs').writeFileSync('data/credentials.json', JSON.stringify(creds, null, 2));
|
||||
require("fs").writeFileSync(
|
||||
"data/credentials.json",
|
||||
JSON.stringify(creds, null, 2),
|
||||
);
|
||||
}
|
||||
function getCredentials() {
|
||||
try {
|
||||
return JSON.parse(require('fs').readFileSync('data/credentials.json', 'utf8'));
|
||||
return JSON.parse(
|
||||
require("fs").readFileSync("data/credentials.json", "utf8"),
|
||||
);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
function spotifyRoutes(app) {
|
||||
app.get('/spotify/callback', async (req,res) => {
|
||||
app.get("/spotify/callback", async (req, res) => {
|
||||
const code = req.query.code || null;
|
||||
const state = req.query.state || null;
|
||||
|
||||
|
@ -166,7 +169,7 @@ function spotifyRoutes(app) {
|
|||
.then((auth) => {
|
||||
// console.log(auth);
|
||||
authStuff = auth;
|
||||
saveCredentials(auth)
|
||||
saveCredentials(auth);
|
||||
token = auth.access_token;
|
||||
if (auth.expires_in) {
|
||||
setTimeout(() => {
|
||||
|
@ -174,15 +177,15 @@ function spotifyRoutes(app) {
|
|||
}, auth.expires_in * 1000);
|
||||
}
|
||||
res.status(200).end("Successfully logged in!");
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
function addSongToPlaylist(url) {
|
||||
fetchWebApi('v1/playlists/3gRv97fvllFFLVdCH6XzsE/tracks', 'POST', {
|
||||
fetchWebApi("v1/playlists/3gRv97fvllFFLVdCH6XzsE/tracks", "POST", {
|
||||
uris: [url],
|
||||
position: 0,
|
||||
})
|
||||
});
|
||||
}
|
||||
module.exports = {
|
||||
getLoginUrl,
|
||||
|
@ -190,7 +193,7 @@ function addSongToPlaylist(url) {
|
|||
saveCredentials,
|
||||
getCredentials,
|
||||
spotifyRoutes,
|
||||
addSongToPlaylist
|
||||
addSongToPlaylist,
|
||||
|
||||
// getToken
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue