changed social bot list to array
This commit is contained in:
parent
d2c6acaed5
commit
6d071ae034
2 changed files with 14 additions and 9 deletions
|
@ -3,26 +3,32 @@ const { EMBED, BROWSER, SOCIAL } = require('../constants/request_types.js');
|
||||||
|
|
||||||
function headersMatchesSocialBotList (headers) {
|
function headersMatchesSocialBotList (headers) {
|
||||||
const userAgent = headers['user-agent'];
|
const userAgent = headers['user-agent'];
|
||||||
const socialBotList = {
|
const socialBotList = [
|
||||||
'facebookexternalhit': 1,
|
'facebookexternalhit',
|
||||||
'Twitterbot' : 1,
|
'Twitterbot',
|
||||||
};
|
];
|
||||||
return socialBotList[userAgent];
|
for (let i = 0; i < socialBotList.length; i++) {
|
||||||
|
if (userAgent.indexOf(socialBotList[i]) >= 0) {
|
||||||
|
logger.debug('request is from social bot:', socialBotList[i]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clientAcceptsHtml ({accept}) {
|
function clientAcceptsHtml ({accept}) {
|
||||||
return accept && accept.match(/text\/html/);
|
return accept && accept.match(/text\/html/);
|
||||||
};
|
}
|
||||||
|
|
||||||
function requestIsFromBrowser (headers) {
|
function requestIsFromBrowser (headers) {
|
||||||
return headers['user-agent'] && headers['user-agent'].match(/Mozilla/);
|
return headers['user-agent'] && headers['user-agent'].match(/Mozilla/);
|
||||||
};
|
}
|
||||||
|
|
||||||
function clientWantsAsset ({accept, range}) {
|
function clientWantsAsset ({accept, range}) {
|
||||||
const imageIsWanted = accept && accept.match(/image\/.*/) && !accept.match(/text\/html/) && !accept.match(/text\/\*/);
|
const imageIsWanted = accept && accept.match(/image\/.*/) && !accept.match(/text\/html/) && !accept.match(/text\/\*/);
|
||||||
const videoIsWanted = accept && range;
|
const videoIsWanted = accept && range;
|
||||||
return imageIsWanted || videoIsWanted;
|
return imageIsWanted || videoIsWanted;
|
||||||
};
|
}
|
||||||
|
|
||||||
const determineRequestType = (hasFileExtension, headers) => {
|
const determineRequestType = (hasFileExtension, headers) => {
|
||||||
let responseType;
|
let responseType;
|
||||||
|
|
|
@ -12,7 +12,6 @@ const torCheck = (req, res, next) => {
|
||||||
raw: true,
|
raw: true,
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
logger.debug('tor check results:', result);
|
|
||||||
if (result.length >= 1) {
|
if (result.length >= 1) {
|
||||||
logger.info('Tor request blocked:', ip);
|
logger.info('Tor request blocked:', ip);
|
||||||
const failureResponse = {
|
const failureResponse = {
|
||||||
|
|
Loading…
Reference in a new issue