changed social bot list to array #504

Merged
bones7242 merged 2 commits from fix-social-botlist into master 2018-06-29 21:54:10 +02:00
bones7242 commented 2018-06-29 20:28:20 +02:00 (Migrated from github.com)

changing social bot check back to an array instead of object, because the check needs to be non-exact.
in the below code, it only returns true if the user agent string is an exact match

const socialBotList = {
    'facebookexternalhit': 1,
    'Twitterbot': 1,
}
​
if (socialBotList[userAgent]) {
  logger.debug();
  return true;
} else {
  return false;
}

in the below version, it will catch any string that contains the social bot name. e.g. facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_u atext.php) or Twitterbot/1.0. This will mean a change to Twitterbot/2.0 or related will not require a change in this code.

const socialBotList = [
  'facebookexternalhit',
  'Twitterbot',
];
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;
  }
}
changing social bot check back to an array instead of object, because the check needs to be non-exact. in the below code, it only returns true if the user agent string is an exact match ``` const socialBotList = { 'facebookexternalhit': 1, 'Twitterbot': 1, } ​ if (socialBotList[userAgent]) { logger.debug(); return true; } else { return false; } ``` in the below version, it will catch any string that contains the social bot name. e.g. ` facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_u atext.php)` or `Twitterbot/1.0`. This will mean a change to `Twitterbot/2.0` or related will not require a change in this code. ``` const socialBotList = [ 'facebookexternalhit', 'Twitterbot', ]; 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; } } ```
neb-b commented 2018-06-29 20:36:01 +02:00 (Migrated from github.com)

Ah that was my mistake. Guess I didn't look close enough.

You could use if (userAgent.includes(socialBotList[i])) { instead to make it a little simpler.

Ah that was my mistake. Guess I didn't look close enough. You could use ` if (userAgent.includes(socialBotList[i])) {` instead to make it a little simpler.
neb-b (Migrated from github.com) approved these changes 2018-06-29 20:36:08 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: LBRYCommunity/spee.ch#504
No description provided.