Add a way to block some urls to avoid spam (#219)

Spam blocker
This commit is contained in:
Gaël Métais
2017-01-08 22:38:34 +08:00
committed by GitHub
parent ecbbbc2d6b
commit f76d597cbf
6 changed files with 51 additions and 3 deletions
+17
View File
@@ -23,6 +23,13 @@ var ApiController = function(app) {
req.body.url = 'http://' + req.body.url;
}
// Block requests to unwanted websites (=spam)
if (isBlocked(req.body.url)) {
console.error('Test blocked for URL: %s', req.body.url);
res.status(403).send('Forbidden');
return;
}
// Grab the test parameters and generate a random run ID
var run = {
runId: (Date.now()*1000 + Math.round(Math.random()*1000)).toString(36),
@@ -86,6 +93,7 @@ var ApiController = function(app) {
return ylt(run.params.url, runOptions);
})
// Phantomas completed, let's save the screenshot if any
.then(function(data) {
@@ -327,6 +335,15 @@ var ApiController = function(app) {
});
});
function isBlocked(url) {
if (!serverSettings.blockedUrls) {
return false;
}
return serverSettings.blockedUrls.some(function(blockedUrl) {
return (url.indexOf(blockedUrl) === 0);
});
}
};
module.exports = ApiController;