Added email spamming throttle

This commit is contained in:
2019-05-09 10:14:12 +10:00
parent bbecd3e3bf
commit 366a415c8a
4 changed files with 72 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
let CronJob = require('cron').CronJob;
let emails = [];
function throttle(email) {
emails[email] = new Date();
}
function isThrottled(email) {
if (emails[email] === undefined) {
return false;
}
if ( (emails[email] - new Date()) / 1000 > 3) { //3 seconds
return false;
}
return true;
}
//clear the memory once a day
let job = new CronJob('0 7 * * * *', () => {
emails = [];
});
job.start();
module.exports = {
throttle: throttle,
isThrottled: isThrottled
};