Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nleush committed Oct 2, 2024
2 parents 99802ae + dcaab2f commit a23effb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 43 deletions.
2 changes: 1 addition & 1 deletion config.local.js.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export default {
youtube: {
// api_key: "INSERT YOUR VALUE",
// parts: [ "snippet", "player" ], // list of fields you want to use in the request, in most cases you only need those two
get_params: "?rel=0&showinfo=1" // https://developers.google.com/youtube/player_parameters,
get_params: "?rel=0&showinfo=1", // https://developers.google.com/youtube/player_parameters,
fix_shorts_in_eu: true // Avoid consent redirect for EU servers
},
vimeo: {
Expand Down
83 changes: 47 additions & 36 deletions lib/plugins/system/oembed/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,60 @@ function fixOembedIframeAttributes(obj) {
}

function _getOembedIframe(oembed) {
if (!oembed.html) {
return null;
}

if (typeof oembed._iframe === 'undefined') {

// Allow encoded entities if they start from $lt;
var html = oembed.html5 || oembed.html;
if (/^<$/i.test(html)) {
html = entities.decodeHTML(html);
}
var _iframe = null;

if (oembed.html5 || oembed.html) {

// Allow encoded entities if they start from $lt;
var html = oembed.html5 || oembed.html;
if (/^<$/i.test(html)) {
html = entities.decodeHTML(html);
}

var $container = cheerio('<div>');
try {
$container.html(html);
} catch (ex) {}
var $iframe = $container.find('iframe');

if ($iframe.length === 2 && /<iframe>$/i.test(html)) {
// Forgive mis-closed iFrame tag
$iframe = $iframe.first();
}

var $container = cheerio('<div>');
try {
$container.html(html);
} catch (ex) {}
var $iframe = $container.find('iframe');
if ($iframe.length === 1) {
_iframe = fixOembedIframeAttributes($iframe[0].attribs);
_iframe.placeholder = oembed.thumbnail_url;
}

if ($iframe.length === 2 && /<iframe>$/i.test(html)) {
// Forgive mis-closed iFrame tag
$iframe = $iframe.first();
// When oembed is in fact iframe from domain fallbacks on oEmbedError
} else if (oembed.src) {
_iframe = oembed;
}

if ($iframe.length === 1) {
oembed._iframe = fixOembedIframeAttributes($iframe[0].attribs);

if (oembed._iframe && oembed._iframe.src) {
var src = URL.parse(oembed._iframe.src, true);
oembed._iframe.host = src.host;
oembed._iframe.pathname = src.pathname;
oembed._iframe.path = src.path;
oembed._iframe.query = src.query;
oembed._iframe.placeholder = oembed.thumbnail_url;
oembed._iframe.replaceQuerystring = function(params) {
var qs = querystring.stringify({...oembed._iframe.query, ...params});
return oembed._iframe.src.replace(/\?.*$/, '') + (qs ? '?' + qs : '');
}
oembed._iframe.assignQuerystring = function(params) {
var qs = querystring.stringify(params);
return oembed._iframe.src.replace(/\?.*$/, '') + (qs ? '?' + qs : '');
}
if (_iframe && _iframe.src) {
var src = URL.parse(_iframe.src, true);
_iframe.host = src.host;
_iframe.pathname = src.pathname;
_iframe.path = src.path;
_iframe.query = src.query;
_iframe.replaceQuerystring = function(params) {
var qs = querystring.stringify({..._iframe.query, ...params});
return _iframe.src.replace(/\?.*$/, '') + (qs ? '?' + qs : '');
}
_iframe.assignQuerystring = function(params) {
var qs = querystring.stringify(params);
return oembed._iframe.src.replace(/\?.*$/, '') + (qs ? '?' + qs : '');
}
} else {
oembed._iframe = null;
_iframe = null;
}
}

oembed._iframe = _iframe ? {..._iframe} : null;
}

return oembed._iframe;
}
Expand All @@ -99,6 +108,8 @@ export default {

provides: ['self', 'oembedError'],

getIframe: _getOembedIframe, // available via export for fallbacks as plugins['oembed'].getIframe(obj)

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

var href = oembedLinks[0].href;
Expand Down
10 changes: 10 additions & 0 deletions lib/plugins/validators/async/21_checkContentType.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ export default {
link.error = 'Adobe Flash Player is no longer supported';
}

if (data.type?.toLowerCase() == 'application/octet-stream'
&& link.rel?.indexOf(CONFIG.R.player) > -1
&& link.accept && link.accept instanceof Array
&& link.accept.indexOf('video/*') > -1) {
data.type = CONFIG.T.video_mp4;
if (!link.message) {
link.message = 'Showing application/octet-stream as MP4';
}
}

/** accept-ranges is misconfigured in many cases (especially via CloudFront). Plus, browsers would try and download first range of MP4 file anyway, even if the header isn't set
if (data.type == CONFIG.T.video_mp4 && !/bytes/i.test(data.accept_ranges)) {
link.error = 'MP4s should allow partial download via accept ranges';
Expand Down
13 changes: 7 additions & 6 deletions plugins/domains/soundcloud.com/soundcloud-oembed-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ export default {

provides: ['__allow_soundcloud_meta', 'iframe'],

getData: function(oembedError, twitter, options, cb) {
if (oembedError === 403 && !options.getProviderOptions('soundcloud.disable_private', false) && twitter.player) {
getData: function(oembedError, twitter, options, plugins, cb) {
var disable_private = options.getProviderOptions('soundcloud.disable_private', false)
if (oembedError === 403 && !disable_private && twitter.player) {
return cb(null, {
__allow_soundcloud_meta: true,
iframe: {
src: twitter.player.value,
iframe: plugins['oembed'].getIframe({
src: twitter.player.value?.replace('origin=twitter', 'origin=iframely'),
height: twitter.player.height
},
}),
message: "Contact support to disable private Soundcloud audio."
});
} else if (oembedError === 403 && options.getProviderOptions('soundcloud.disable_private', false)) {
} else if (oembedError === 403 && disable_private) {
return cb({
responseError: oembedError
});
Expand Down

0 comments on commit a23effb

Please sign in to comment.