fix(embed): fix crash when API returns relative URL
Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2493>
This commit is contained in:
parent
1e3c8081b5
commit
58d48a061e
|
@ -0,0 +1 @@
|
||||||
|
Fixed embedded player crash when API returns relative listen URL. (#2163)
|
|
@ -73,7 +73,13 @@
|
||||||
// NOTE: Add a transcoded MP3 src at the end for browsers
|
// NOTE: Add a transcoded MP3 src at the end for browsers
|
||||||
// that do not support other codecs to be able to play it :)
|
// that do not support other codecs to be able to play it :)
|
||||||
if (sources.length > 0 && !sources.some(({ mimetype }) => mimetype === 'audio/mpeg')) {
|
if (sources.length > 0 && !sources.some(({ mimetype }) => mimetype === 'audio/mpeg')) {
|
||||||
const url = new URL(sources[0].listen_url)
|
const source = sources[0].listen_url
|
||||||
|
const url = new URL(source.test(/^https?:/)
|
||||||
|
? source
|
||||||
|
: source[0] === '/'
|
||||||
|
? `${baseUrl}${source}`
|
||||||
|
: `${baseUrl}/${source}`
|
||||||
|
)
|
||||||
url.searchParams.set('to', 'mp3')
|
url.searchParams.set('to', 'mp3')
|
||||||
sources.push({ mimetype: 'audio/mpeg', listen_url: url.toString() })
|
sources.push({ mimetype: 'audio/mpeg', listen_url: url.toString() })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue