Skip to content

Commit c13ea9c

Browse files
committed
Fixed extra comma on client example, cleaned up server file
1 parent e33920d commit c13ea9c

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

client/page.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ $.ajax({
3232
//authors[i] = {"name": data.body.item.artists[i].name, "url": data.body.item.artists[i].external_urls.spotify};
3333
authors += resp.urls.artists[i].name + ", ";
3434
}
35+
36+
//Remove the last , at the end of the authors string
37+
authors = authors.substring(0, authors.length - 2);
38+
3539
} else {
3640
authors += resp.urls.artists[0].name
3741
}

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/app.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
const express = require("express");
2424
const SpotifyWebApi = require("spotify-web-api-node");
2525
const config = require("./config.json");
26-
var tokenExpireEpoch = 0;
2726
var cors = require('cors');
2827
const e = require("express");
2928

29+
var tokenExpireEpoch;
3030
var scopes = ['user-read-currently-playing'],
3131
redirectUri = 'http://localhost:1337/callback',
3232
clientId = config.ClientToken,
@@ -39,30 +39,29 @@ var spotifyApi = new SpotifyWebApi({
3939
clientSecret: config.ClientSecret
4040
});
4141

42-
//var authURL = spotifyApi.createAuthorizeURL(scopes,state);
43-
//console.log(authURL);
44-
45-
//var accessToken = "";
4642
var refreshToken = config.RefreshToken;
47-
48-
//spotifyApi.setAccessToken(accessToken);
4943
spotifyApi.setRefreshToken(refreshToken);
5044

5145
const app = express()
5246
app.use(cors())
5347

54-
function pleaseRefreshlmao() {
48+
function refreshAccToken() {
49+
var done;
5550
//Check to see if a token exists on the config.
5651
spotifyApi.refreshAccessToken().then(
5752
function (data) {
5853
console.log("The token has been refresh!");
5954
tokenExpireEpoch = Math.floor(Date.now() / 1000);
6055
spotifyApi.setAccessToken(data.body['access_token']);
56+
done = true
6157
},
6258
function (err) {
6359
console.log("Couldn't refresh token! Error:", err);
60+
done = false;
6461
}
6562
)
63+
64+
return done;
6665
}
6766

6867
function generateToken() {
@@ -118,7 +117,7 @@ app.get('/api/currentplaying', function (req, res) {
118117
var timesincetoken = Number(Math.floor(Date.now() / 1000) - tokenExpireEpoch);
119118
//console.log(timesincetoken);
120119
if (timesincetoken >= 3600) {
121-
pleaseRefreshlmao();
120+
refreshAccToken();
122121
getPlaying(req, res);
123122
} else {
124123
//console.log("Not hit epoch yet");
@@ -163,7 +162,8 @@ app.get('/callback', function (req, res) {
163162
if (refreshToken == "") {
164163
generateToken();
165164
} else {
166-
pleaseRefreshlmao();
165+
var a = refreshAccToken();
166+
console.log(a);
167167
}
168168

169169
app.listen(1337);

0 commit comments

Comments
 (0)