Skip to content

Commit bab08d0

Browse files
authored
domains: fix private Soundclouds (#560)
by adding required oEmbed iframe `assignQuerystring` method that is used in main Soundcloud plugin
1 parent ad45915 commit bab08d0

File tree

2 files changed

+54
-42
lines changed

2 files changed

+54
-42
lines changed

lib/plugins/system/oembed/oembed.js

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,51 +31,60 @@ function fixOembedIframeAttributes(obj) {
3131
}
3232

3333
function _getOembedIframe(oembed) {
34-
if (!oembed.html) {
35-
return null;
36-
}
34+
3735
if (typeof oembed._iframe === 'undefined') {
3836

39-
// Allow encoded entities if they start from $lt;
40-
var html = oembed.html5 || oembed.html;
41-
if (/^<$/i.test(html)) {
42-
html = entities.decodeHTML(html);
43-
}
37+
var _iframe = null;
38+
39+
if (oembed.html5 || oembed.html) {
40+
41+
// Allow encoded entities if they start from $lt;
42+
var html = oembed.html5 || oembed.html;
43+
if (/^<$/i.test(html)) {
44+
html = entities.decodeHTML(html);
45+
}
46+
47+
var $container = cheerio('<div>');
48+
try {
49+
$container.html(html);
50+
} catch (ex) {}
51+
var $iframe = $container.find('iframe');
52+
53+
if ($iframe.length === 2 && /<iframe>$/i.test(html)) {
54+
// Forgive mis-closed iFrame tag
55+
$iframe = $iframe.first();
56+
}
4457

45-
var $container = cheerio('<div>');
46-
try {
47-
$container.html(html);
48-
} catch (ex) {}
49-
var $iframe = $container.find('iframe');
58+
if ($iframe.length === 1) {
59+
_iframe = fixOembedIframeAttributes($iframe[0].attribs);
60+
_iframe.placeholder = oembed.thumbnail_url;
61+
}
5062

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

56-
if ($iframe.length === 1) {
57-
oembed._iframe = fixOembedIframeAttributes($iframe[0].attribs);
58-
59-
if (oembed._iframe && oembed._iframe.src) {
60-
var src = URL.parse(oembed._iframe.src, true);
61-
oembed._iframe.host = src.host;
62-
oembed._iframe.pathname = src.pathname;
63-
oembed._iframe.path = src.path;
64-
oembed._iframe.query = src.query;
65-
oembed._iframe.placeholder = oembed.thumbnail_url;
66-
oembed._iframe.replaceQuerystring = function(params) {
67-
var qs = querystring.stringify({...oembed._iframe.query, ...params});
68-
return oembed._iframe.src.replace(/\?.*$/, '') + (qs ? '?' + qs : '');
69-
}
70-
oembed._iframe.assignQuerystring = function(params) {
71-
var qs = querystring.stringify(params);
72-
return oembed._iframe.src.replace(/\?.*$/, '') + (qs ? '?' + qs : '');
73-
}
68+
if (_iframe && _iframe.src) {
69+
var src = URL.parse(_iframe.src, true);
70+
_iframe.host = src.host;
71+
_iframe.pathname = src.pathname;
72+
_iframe.path = src.path;
73+
_iframe.query = src.query;
74+
_iframe.replaceQuerystring = function(params) {
75+
var qs = querystring.stringify({..._iframe.query, ...params});
76+
return _iframe.src.replace(/\?.*$/, '') + (qs ? '?' + qs : '');
77+
}
78+
_iframe.assignQuerystring = function(params) {
79+
var qs = querystring.stringify(params);
80+
return oembed._iframe.src.replace(/\?.*$/, '') + (qs ? '?' + qs : '');
7481
}
7582
} else {
76-
oembed._iframe = null;
83+
_iframe = null;
7784
}
78-
}
85+
86+
oembed._iframe = {..._iframe};
87+
}
7988

8089
return oembed._iframe;
8190
}
@@ -99,6 +108,8 @@ export default {
99108

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

111+
getIframe: _getOembedIframe, // available via export for fallbacks as plugins['oembed'].getIframe(obj)
112+
102113
getData: function(url, oembedLinks, options, cb) {
103114

104115
var href = oembedLinks[0].href;

plugins/domains/soundcloud.com/soundcloud-oembed-error.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ export default {
22

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

5-
getData: function(oembedError, twitter, options, cb) {
6-
if (oembedError === 403 && !options.getProviderOptions('soundcloud.disable_private', false) && twitter.player) {
5+
getData: function(oembedError, twitter, options, plugins, cb) {
6+
var disable_private = options.getProviderOptions('soundcloud.disable_private', false)
7+
if (oembedError === 403 && !disable_private && twitter.player) {
78
return cb(null, {
89
__allow_soundcloud_meta: true,
9-
iframe: {
10-
src: twitter.player.value,
10+
iframe: plugins['oembed'].getIframe({
11+
src: twitter.player.value?.replace('origin=twitter', 'origin=iframely'),
1112
height: twitter.player.height
12-
},
13+
}),
1314
message: "Contact support to disable private Soundcloud audio."
1415
});
15-
} else if (oembedError === 403 && options.getProviderOptions('soundcloud.disable_private', false)) {
16+
} else if (oembedError === 403 && disable_private) {
1617
return cb({
1718
responseError: oembedError
1819
});

0 commit comments

Comments
 (0)