Added rate limit per day per IP.

This commit is contained in:
Ajay Ramachandran
2019-07-21 22:06:01 -04:00
parent 5a5118a7b0
commit 930c0bc6a3

View File

@@ -105,9 +105,17 @@ app.get('/api/postVideoSponsorTimes', function (req, res) {
//get current time
let timeSubmitted = Date.now();
let yesterday = timeSubmitted - 86400000;
//check to see if this ip has submitted too many sponsors today
db.prepare("SELECT COUNT(*) as count FROM sponsorTimes WHERE hashedIP = ? AND videoID = ? AND timeSubmitted > ?").get([hashedIP, videoID, yesterday], function(err, row) {
if (row.count >= 10) {
//too many sponsors for the same video from the same ip address
res.sendStatus(429);
} else {
//check to see if the user has already submitted sponsors for this video
db.prepare("SELECT UUID FROM sponsorTimes WHERE userID = ? and videoID = ?").all([userID, videoID], function(err, rows) {
if (rows.length >= 4) {
db.prepare("SELECT COUNT(*) as count FROM sponsorTimes WHERE userID = ? and videoID = ?").get([userID, videoID], function(err, row) {
if (row.count >= 4) {
//too many sponsors for the same video from the same user
res.sendStatus(429);
} else {
@@ -126,6 +134,8 @@ app.get('/api/postVideoSponsorTimes', function (req, res) {
});
}
});
}
});
});
//voting endpoint