mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 20:47:02 +03:00
Added voting endpoint.
This commit is contained in:
34
index.js
34
index.js
@@ -106,6 +106,40 @@ app.get('/api/postVideoSponsorTimes', function (req, res) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//voting endpoint
|
||||||
|
app.get('/api/voteOnSponsorTime', function (req, res) {
|
||||||
|
let UUID = req.query.UUID;
|
||||||
|
let userID = req.query.userID;
|
||||||
|
let type = req.query.type;
|
||||||
|
|
||||||
|
if (UUID == undefined || userID == undefined || type == undefined) {
|
||||||
|
//invalid request
|
||||||
|
res.sendStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-1 for downvote, 1 for upvote. Maybe more depending on reputation in the future
|
||||||
|
let incrementAmount = 0;
|
||||||
|
|
||||||
|
//don't use userID for now, and just add the vote
|
||||||
|
if (type == 1) {
|
||||||
|
//upvote
|
||||||
|
incrementAmount = 1;
|
||||||
|
} else if (type == 0) {
|
||||||
|
//downvote
|
||||||
|
incrementAmount = -1;
|
||||||
|
} else {
|
||||||
|
//unrecongnised type of vote
|
||||||
|
req.sendStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
db.prepare("UPDATE sponsorTimes SET votes = votes + ? WHERE UUID = ?").run(incrementAmount, UUID);
|
||||||
|
|
||||||
|
//added to db
|
||||||
|
res.sendStatus(200);
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/database.db', function (req, res) {
|
app.get('/database.db', function (req, res) {
|
||||||
res.sendFile("./databases/sponsorTimes.db", { root: __dirname });
|
res.sendFile("./databases/sponsorTimes.db", { root: __dirname });
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user