diff --git a/plugins/custom/fb-error.js b/plugins/custom/fb-error.js index 516d95a0e..66b0fe4f8 100644 --- a/plugins/custom/fb-error.js +++ b/plugins/custom/fb-error.js @@ -6,7 +6,7 @@ export default { // Though the errors we actually need are not in the doc... const KNOWN_CODES = { 2: 408, // Downtime - 24: 404, // Seems to be 404 for Instagrams + // 24: 404, // 404s and restricted for Instagrams, handled separately 100: 404, // https://developers.facebook.com/docs/graph-api/reference/oembed-video/ 901: 417, // ./oembed-post/, ./oembed-page/ @@ -16,52 +16,85 @@ export default { 368: 451 // Temporary blocked } - let result = {}; // When left empty - it allows a fallback to generic parsers and get the accurate http code. - const fbError = oembedError.body && oembedError.body.error || {}; + const fbError = oembedError.body?.error || {}; - var error = fbError.code - && KNOWN_CODES[fbError.code] /* is defined */ + const error = fbError.code && KNOWN_CODES[fbError.code] /* is a known error code */ ? KNOWN_CODES[fbError.code] : null; - if (!error && - (!oembedError.body // Connection issue like ERR_HTTP2_STREAM_ERROR - || fbError.is_transient) // Unexpected transient error - ) { - - error = 408; - } - - if (fbError.code === 2 /* downtime */ && fbError.is_transient && options.cache_ttl === 0) { - // handle error elsewhere, e.g. fall back to generic parsers - error = null; - } - - const isVideo = /(?:videos?|watch)/i.test(url); - - if (error && !isVideo) { - result.responseError = error; - } + let result = {}; if (error === 415) { - result.message = CONFIG.FB_ERROR_MESSAGE || - "HEADS UP: Facebook & Instagram now require your own access_token configured. " - + " See https://github.com/itteco/iframely/issues/284"; - } else if (isVideo && error === 404) { - result.message = "This video cannot be embedded."; - result.fallback = "generic"; + result = { + responseError: 415, + message: CONFIG.FB_ERROR_MESSAGE || + "HEADS UP: Facebook & Instagram now require your own access_token configured. " + + " See https://github.com/itteco/iframely/issues/284" + }; + + // FB video with disabled embedding + } else if (error === 404 && /(?:videos?|watch)/i.test(url)) { + result = { + fallback: "generic", + message: "This video cannot be embedded." + }; + + // Instagram post with disabled embedding } else if (fbError.error_subcode == 2207046) { - // Instagram's post with disabled embedding - result.message = "Owner has disabled embedding of this post"; - result.fallback = "generic"; - } else if (/endpoint must be reviewed and approved by Facebook/.test(oembedError?.body?.error?.message) - && options.getProviderOptions('facebook.oembed_read_error_msg') - && /^887156172/.test(options.getProviderOptions('facebook.access_token'))) { - - result.message = options.getProviderOptions('facebook.oembed_read_error_msg'); - - } else if ((fbError.error_user_msg || fbError.message) && error !== 404) { - result.message = fbError.error_user_msg || fbError.message; + result = { + fallback: "generic", + message: "Owner has disabled embedding of this post" + }; + + // Instagram post either 404 or private or sensitive + } else if (/instagram/i.test(url) && (fbError.code === 24 || fbError.code === 2 || !fbError.code)) { + result = { + fallback: "generic", + message: fbError.error_user_msg || "Media can't be embedded from private, inactive, and age-restricted accounts" + }; + + // Issues with FB access token + } else if (/endpoint must be reviewed and approved by Facebook/i.test(fbError.message) + || /Invalid OAuth access token/i.test(fbError.message)) { + + result.message = /^(88715617|64356396)/.test(options.getProviderOptions('facebook.access_token')) + ? options.getProviderOptions('facebook.oembed_read_error_msg', fbError.message) + : fbError.message; + + // FB downtime + } else if (fbError.code === 2 && fbError.is_transient) { + if (options.cache_ttl === 0) { + result = { + fallback: 'generic', + message: "Facebook reports a downtime" + }; + } else { + result = { + responseError: 408, + message: "Facebook reports a downtime" + } + } + + // Unexpected unknown transient error. + } else if (!error && options.cache_ttl !== 0 + && (!oembedError.body // Connection issue like ERR_HTTP2_STREAM_ERROR + || fbError.is_transient + )) { + result.responseError = 408; + + // Other known error + } else if (error) { + result.responseError = error; + if (error !== 404 && (fbError.error_user_msg || fbError.message)) { + result.message = fbError.error_user_msg || fbError.message; + } + + // Other unknown error + } else { + result = { + fallback: "generic", + message: fbError.error_user_msg || fbError.message + } } log('Facebook oembed api - error getting oembed for', url, JSON.stringify(fbError), JSON.stringify(result)); diff --git a/plugins/domains/instagram.com/instagram-post-allow-meta.js b/plugins/domains/instagram.com/instagram-post-allow-meta.js index 35cc25e5e..3e076273e 100644 --- a/plugins/domains/instagram.com/instagram-post-allow-meta.js +++ b/plugins/domains/instagram.com/instagram-post-allow-meta.js @@ -9,10 +9,20 @@ export default { && !meta.title && !meta.description && meta['html-title'] === 'Instagram') { return cb({responseStatusCode: 404}) + + } else if ( + // URL from instagram-profile + /^https?:\/\/(?:www\.)?instagram\.com\/([a-zA-Z0-9\._]+)\/?(?:\?.*)?$/i.test(meta.og?.url) + && meta.og?.type === 'profile') { + return cb({responseStatusCode: 403}) + } else { return cb (null, { ipOG: meta.og ? meta.og : {} }) } } + + // private: https://www.instagram.com/tv/Cfv5RV6Ae8bMan9o-CS7vsZGxcmGHuTGvG0jNI0/?igsh=bmI4czZqb2l4NDQx + // deleted: https://www.instagram.com/p/B3A-0uuAhg0/ }; \ No newline at end of file diff --git a/plugins/domains/instagram.com/instagram.com.js b/plugins/domains/instagram.com/instagram.com.js index 6b2d1f2a6..8619d9a7f 100644 --- a/plugins/domains/instagram.com/instagram.com.js +++ b/plugins/domains/instagram.com/instagram.com.js @@ -169,10 +169,6 @@ export default { result.__allowInstagramMeta = true; } - if (urlMatch[1] && urlMatch[1].length > 30) { - result.message = 'This Instagram post is private.'; // IDs longer than 30 is for private posts as of March 11, 2020 - } - if (!options.redirectsHistory && (/^https?:\/\/instagram\.com\//i.test(url) || /^http:\/\/www\.instagram\.com\//i.test(url))) { result.redirect = url.replace(/^http:\/\//, 'https://').replace(/^https:\/\/instagram\.com\//i, 'https://www.instagram.com'); }