fix(embed): fix crash when API returns relative URL

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2493>
environments/review-docs-merge-hoc7bt/deployments/18064
Kasper Seweryn 2023-06-16 17:55:05 +00:00 zatwierdzone przez Marge
rodzic 1e3c8081b5
commit 58d48a061e
2 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

@ -0,0 +1 @@
Fixed embedded player crash when API returns relative listen URL. (#2163)

Wyświetl plik

@ -73,7 +73,13 @@
// NOTE: Add a transcoded MP3 src at the end for browsers
// that do not support other codecs to be able to play it :)
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')
sources.push({ mimetype: 'audio/mpeg', listen_url: url.toString() })
}