mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Added user based time saved endpoint.
This commit is contained in:
parent
6ae8001b79
commit
3f55bfea22
1 changed files with 31 additions and 0 deletions
31
index.js
31
index.js
|
@ -548,6 +548,37 @@ app.get('/api/getViewsForUser', function (req, res) {
|
|||
});
|
||||
});
|
||||
|
||||
//Gets all the saved time added up (views * sponsor length) for one userID
|
||||
//Useful to see how much one user has contributed
|
||||
//In minutes
|
||||
app.get('/api/getSavedTimeForUser', function (req, res) {
|
||||
let userID = req.query.userID;
|
||||
|
||||
if (userID == undefined) {
|
||||
//invalid request
|
||||
res.sendStatus(400);
|
||||
return;
|
||||
}
|
||||
|
||||
//hash the userID
|
||||
userID = getHash(userID);
|
||||
|
||||
//up the view count by one
|
||||
db.prepare("SELECT SUM((endTime - startTime) / 60 * views) as minutesSaved FROM sponsorTimes WHERE userID = ?").get(userID, function(err, row) {
|
||||
if (err) console.log(err);
|
||||
|
||||
console.log(userID)
|
||||
|
||||
if (row.minutesSaved != null) {
|
||||
res.send({
|
||||
timeSaved: row.minutesSaved
|
||||
});
|
||||
} else {
|
||||
res.sendStatus(404);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/getTopUsers', function (req, res) {
|
||||
let sortType = req.query.sortType;
|
||||
|
||||
|
|
Loading…
Reference in a new issue