mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-23 16:08:25 +03:00
Added API endpoint to get the username
This commit is contained in:
31
index.js
31
index.js
@@ -252,7 +252,7 @@ app.get('/api/viewedVideoSponsorTime', function (req, res) {
|
||||
});
|
||||
|
||||
//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 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
|
||||
//Useful to see how much one user has contributed
|
||||
app.get('/api/getViewsForUser', function (req, res) {
|
||||
|
||||
Reference in New Issue
Block a user