Merge pull request #504 from lbryio/fix-social-botlist

changed social bot list to array
This commit is contained in:
Bill Bittner 2018-06-29 12:54:10 -07:00 committed by GitHub
commit dc7cda1356
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View file

@ -3,26 +3,32 @@ const { EMBED, BROWSER, SOCIAL } = require('../constants/request_types.js');
function headersMatchesSocialBotList (headers) {
const userAgent = headers['user-agent'];
const socialBotList = {
'facebookexternalhit': 1,
'Twitterbot' : 1,
};
return socialBotList[userAgent];
const socialBotList = [
'facebookexternalhit',
'Twitterbot',
];
for (let i = 0; i < socialBotList.length; i++) {
if (userAgent.includes(socialBotList[i])) {
logger.debug('request is from social bot:', socialBotList[i]);
return true;
}
}
return false;
}
function clientAcceptsHtml ({accept}) {
return accept && accept.match(/text\/html/);
};
}
function requestIsFromBrowser (headers) {
return headers['user-agent'] && headers['user-agent'].match(/Mozilla/);
};
}
function clientWantsAsset ({accept, range}) {
const imageIsWanted = accept && accept.match(/image\/.*/) && !accept.match(/text\/html/) && !accept.match(/text\/\*/);
const videoIsWanted = accept && range;
return imageIsWanted || videoIsWanted;
};
}
const determineRequestType = (hasFileExtension, headers) => {
let responseType;

View file

@ -12,7 +12,6 @@ const torCheck = (req, res, next) => {
raw: true,
})
.then(result => {
logger.debug('tor check results:', result);
if (result.length >= 1) {
logger.info('Tor request blocked:', ip);
const failureResponse = {