Added API endpoint to get the username

This commit is contained in:
Ajay Ramachandran
2019-08-12 23:31:44 -04:00
parent dc33bc33d6
commit 4079419fa8

View File

@@ -252,7 +252,7 @@ app.get('/api/viewedVideoSponsorTime', function (req, res) {
}); });
//To set your username for the stats view //To set your username for the stats view
app.get('/api/setUsername', function (req, res) { app.post('/api/setUsername', function (req, res) {
let userID = req.query.userID; let userID = req.query.userID;
let userName = req.query.username; let userName = req.query.username;
@@ -281,6 +281,35 @@ app.get('/api/setUsername', function (req, res) {
}); });
}); });
//get what username this user has
app.get('/api/getUsername', function (req, res) {
let userID = req.query.userID;
if (userID == undefined) {
//invalid request
res.sendStatus(400);
return;
}
//hash the userID
userID = getHash(userID);
db.prepare("SELECT userName FROM userNames WHERE userID = ?").get(userID, function(err, row) {
if (err) console.log(err);
if (row != null) {
res.send({
userName: row.userName
});
} else {
//no username yet, just send back the userID
res.send({
userName: userID
});
}
});
});
//Gets all the views added up for one userID //Gets all the views added up for one userID
//Useful to see how much one user has contributed //Useful to see how much one user has contributed
app.get('/api/getViewsForUser', function (req, res) { app.get('/api/getViewsForUser', function (req, res) {