Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nleush committed Nov 8, 2024
2 parents febe516 + 52385d2 commit b2ca2f7
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 50 deletions.
113 changes: 73 additions & 40 deletions plugins/custom/fb-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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));
Expand Down
13 changes: 10 additions & 3 deletions plugins/domains/documentcloud.org.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default {
"author",
"og-title",
"og-image",
"og-description"
"og-description",
"oembed-title"
],

// plugin is required to add aspect-ratio and with this fix embeds when used inside iFrame
Expand All @@ -31,10 +32,11 @@ export default {

if (!/DC\-note/.test(html) && !/DC\-embed(?:\-page)?/.test(html)) {
var page = options.getRequestOptions('documentcloud.page', '1');
var title = !!options.getRequestOptions('documentcloud.title', false);

try {
var iframe = oembed.getIframe();
var href = iframe.src;
var href = title ? iframe.replaceQuerystring({ title: 1 }) : iframe.src;

if (page && page !== '1') {
if (href) {
Expand All @@ -51,6 +53,10 @@ export default {
page: {
label: CONFIG.L.page,
value: parseInt (page)
},
title: {
label: 'Show title',
value: title
}
}
} catch (ex) {}
Expand Down Expand Up @@ -95,7 +101,8 @@ export default {
'author',
'canonical',
'og-title',
'og-image'
'og-image',
'oembed-title'
]},
'https://www.documentcloud.org/documents/73991-day-three-documents',
'https://www.documentcloud.org/documents/5766398-ASRS-Reports-for-737-max8.html#document/p2/a486265',
Expand Down
10 changes: 10 additions & 0 deletions plugins/domains/instagram.com/instagram-post-allow-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/
};
4 changes: 0 additions & 4 deletions plugins/domains/instagram.com/instagram.com.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
7 changes: 4 additions & 3 deletions plugins/domains/rapgenius.com.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
var theme = options.getRequestOptions('players.theme', 'light');

return {
html: '<div id="rg_embed_link_' + id + '" class="rg_embed_link" data-song-id="' + id + '"></div><script src="//genius.com/songs/' + id + '/embed.js' +
html: '<div id="rg_embed_link_' + id + '" class="rg_embed_link" data-song-id="' + id + '"></div><script src="https://genius.com/songs/' + id + '/embed.js' +
(theme === 'dark' ? '?dark=1' : '') +'"></script>',

type: CONFIG.T.text_html,
Expand All @@ -40,8 +40,9 @@ export default {
}
},

tests: [{ skipMixins: ["favicon"]},
tests: [
"https://genius.com/Bruce-springsteen-4th-of-july-asbury-park-sandy-lyrics",
"https://genius.com/Beyonce-flawless-remix-lyrics"
"https://genius.com/Beyonce-flawless-remix-lyrics",
"https://genius.com/Mariah-carey-all-i-want-for-christmas-is-you-lyrics"
]
};

0 comments on commit b2ca2f7

Please sign in to comment.