Skip to content

Commit

Permalink
html: fix too_many_redirects handler and use it for FB
Browse files Browse the repository at this point in the history
  • Loading branch information
iparamonau committed Jul 23, 2024
1 parent b925fa7 commit 63d490c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/plugins/system/htmlparser/htmlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
headers: {}
});
} else if (!!options.exposeStatusCode
&& error.message === 'too_many_redirects') {
&& error === 'too_many_redirects') {

cb(null, {
__statusCode: 508, // Hello Instagram, see #503
Expand Down
18 changes: 18 additions & 0 deletions plugins/custom/meta-fallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {

provides: 'meta',

getData: function(url, __statusCode, options, cb) {

return __statusCode !== 429 && __statusCode !== 403 &&__statusCode !== 508

? cb({
responseStatusCode: __statusCode,
})

: cb(null, {
meta: {},
message: `${options.provider || 'Publisher'} is rate-limiting. Meta disabled.`
})
}
};
7 changes: 6 additions & 1 deletion plugins/domains/facebook.com/facebook.thumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default {
'facebook.video'
],

mixins: ['meta-fallback'],

getLink: function(url, __allowFBThumbnail, options, meta) {

var thumbnail = meta.twitter?.image
Expand Down Expand Up @@ -58,6 +60,8 @@ export default {
&& options.getProviderOptions('facebook.thumbnail', true) && !/comment_id=/.test(oembed.html)) {

options.followHTTPRedirect = true; // avoid security re-directs of URLs if any
options.exposeStatusCode = true;
options.provider = 'Facebook';

return {
__allowFBThumbnail: true
Expand All @@ -67,6 +71,7 @@ export default {

tests: [{
noFeeds: true,
skipMethods: ['getData', 'getLink']
skipMethods: ['getData', 'getLink'],
skipMixins: ['meta-fallback']
}]
};

0 comments on commit 63d490c

Please sign in to comment.