mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 20:17:02 +03:00
Added rate limit per day per IP.
This commit is contained in:
14
index.js
14
index.js
@@ -105,9 +105,17 @@ app.get('/api/postVideoSponsorTimes', function (req, res) {
|
|||||||
//get current time
|
//get current time
|
||||||
let timeSubmitted = Date.now();
|
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
|
//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) {
|
db.prepare("SELECT COUNT(*) as count FROM sponsorTimes WHERE userID = ? and videoID = ?").get([userID, videoID], function(err, row) {
|
||||||
if (rows.length >= 4) {
|
if (row.count >= 4) {
|
||||||
//too many sponsors for the same video from the same user
|
//too many sponsors for the same video from the same user
|
||||||
res.sendStatus(429);
|
res.sendStatus(429);
|
||||||
} else {
|
} else {
|
||||||
@@ -126,6 +134,8 @@ app.get('/api/postVideoSponsorTimes', function (req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//voting endpoint
|
//voting endpoint
|
||||||
|
|||||||
Reference in New Issue
Block a user