|
|
@ -20,15 +20,15 @@ app.listen(port, () => { console.log(`Big brother is listening on port ${port}`)
|
|
|
|
|
|
|
|
|
|
|
|
//#region ACCESS TOKEN
|
|
|
|
//#region ACCESS TOKEN
|
|
|
|
app.get('/settings/deactivate', async (req,res) => {
|
|
|
|
app.get('/settings/deactivate', async (req,res) => {
|
|
|
|
const client = mariadb.createPool({
|
|
|
|
const code = req.query.code;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const pool = mariadb.createPool({
|
|
|
|
host: 'felixmielcarek-bigbrotherdb',
|
|
|
|
host: 'felixmielcarek-bigbrotherdb',
|
|
|
|
user: process.env.MARIADB_USER,
|
|
|
|
user: process.env.MARIADB_USER,
|
|
|
|
database: process.env.MARIADB_DATABASE,
|
|
|
|
database: process.env.MARIADB_DATABASE,
|
|
|
|
password: process.env.MARIADB_PASSWORD
|
|
|
|
password: process.env.MARIADB_PASSWORD
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const code = req.query.code;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var authOptions = {
|
|
|
|
var authOptions = {
|
|
|
|
url: 'https://accounts.spotify.com/api/token', method: 'post', json: true,
|
|
|
|
url: 'https://accounts.spotify.com/api/token', method: 'post', json: true,
|
|
|
|
data: { code: code, redirect_uri: redirectUri, grant_type: 'authorization_code' },
|
|
|
|
data: { code: code, redirect_uri: redirectUri, grant_type: 'authorization_code' },
|
|
|
@ -41,29 +41,30 @@ app.get('/settings/deactivate', async (req,res) => {
|
|
|
|
const response1 = await axios(authOptions);
|
|
|
|
const response1 = await axios(authOptions);
|
|
|
|
const accessToken = response1.data.access_token
|
|
|
|
const accessToken = response1.data.access_token
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let conn;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = await pool.getConnection()
|
|
|
|
const response2 = await axios.get(`https://api.spotify.com/v1/me`, { headers: { 'Authorization': 'Bearer ' + accessToken, } });
|
|
|
|
const response2 = await axios.get(`https://api.spotify.com/v1/me`, { headers: { 'Authorization': 'Bearer ' + accessToken, } });
|
|
|
|
|
|
|
|
|
|
|
|
await client.getConnection()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sqlQuery = `
|
|
|
|
const sqlQuery = `
|
|
|
|
DELETE FROM users
|
|
|
|
DELETE FROM users
|
|
|
|
WHERE spotifyid = ?;
|
|
|
|
WHERE spotifyid = ?;
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
client.query(sqlQuery, [response2.data.SpotifyId], (err, res) => {
|
|
|
|
conn.query(sqlQuery, [response2.data.SpotifyId], (err, res) => {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
console.error('Error executing query', err);
|
|
|
|
console.error('Error executing query', err);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('Data deleted successfully');
|
|
|
|
console.log('Data deleted successfully');
|
|
|
|
client.end();
|
|
|
|
conn.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (error) { console.log('Error getting user Spotify id') }
|
|
|
|
} catch (error) { console.log('Error getting user Spotify id') }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/', async (req, res) => {
|
|
|
|
app.get('/', async (req, res) => {
|
|
|
|
const client = mariadb.createPool({
|
|
|
|
const pool = mariadb.createPool({
|
|
|
|
host: 'felixmielcarek-bigbrotherdb',
|
|
|
|
host: 'felixmielcarek-bigbrotherdb',
|
|
|
|
user: process.env.MARIADB_USER,
|
|
|
|
user: process.env.MARIADB_USER,
|
|
|
|
database: process.env.MARIADB_DATABASE,
|
|
|
|
database: process.env.MARIADB_DATABASE,
|
|
|
@ -85,7 +86,11 @@ app.get('/', async (req, res) => {
|
|
|
|
const accessToken = response1.data.access_token
|
|
|
|
const accessToken = response1.data.access_token
|
|
|
|
const refreshToken = response1.data.refresh_token
|
|
|
|
const refreshToken = response1.data.refresh_token
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let conn;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = await pool.getConnection()
|
|
|
|
|
|
|
|
|
|
|
|
const response2 = await axios.get(`https://api.spotify.com/v1/me`, { headers: { 'Authorization': 'Bearer ' + accessToken, } });
|
|
|
|
const response2 = await axios.get(`https://api.spotify.com/v1/me`, { headers: { 'Authorization': 'Bearer ' + accessToken, } });
|
|
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
const data = {
|
|
|
@ -94,8 +99,6 @@ app.get('/', async (req, res) => {
|
|
|
|
RefreshToken: refreshToken
|
|
|
|
RefreshToken: refreshToken
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
await client.getConnection()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sqlQuery = `
|
|
|
|
const sqlQuery = `
|
|
|
|
INSERT INTO users (spotifyid, accesstoken, refreshtoken)
|
|
|
|
INSERT INTO users (spotifyid, accesstoken, refreshtoken)
|
|
|
|
VALUES (?, ?, ?)
|
|
|
|
VALUES (?, ?, ?)
|
|
|
@ -104,13 +107,13 @@ app.get('/', async (req, res) => {
|
|
|
|
refreshtoken = VALUES(refreshtoken);
|
|
|
|
refreshtoken = VALUES(refreshtoken);
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
client.query(sqlQuery, [data.SpotifyId, data.AccessToken, data.RefreshToken], (err, res) => {
|
|
|
|
conn.query(sqlQuery, [data.SpotifyId, data.AccessToken, data.RefreshToken], (err, res) => {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
console.error('Error executing query', err);
|
|
|
|
console.error('Error executing query', err);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('Data inserted/updated successfully');
|
|
|
|
console.log('Data inserted/updated successfully');
|
|
|
|
client.end();
|
|
|
|
conn.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (error) { console.log('Error getting user Spotify id') }
|
|
|
|
} catch (error) { console.log('Error getting user Spotify id') }
|
|
|
|
});
|
|
|
|
});
|
|
|
|