From 58d48a061ed2d31ba9d4cd74b684964f324f09b4 Mon Sep 17 00:00:00 2001 From: Kasper Seweryn Date: Fri, 16 Jun 2023 17:55:05 +0000 Subject: [PATCH] fix(embed): fix crash when API returns relative URL Part-of: --- changes/changelog.d/2163.bugfix | 1 + front/public/embed.html | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changes/changelog.d/2163.bugfix diff --git a/changes/changelog.d/2163.bugfix b/changes/changelog.d/2163.bugfix new file mode 100644 index 000000000..aea770317 --- /dev/null +++ b/changes/changelog.d/2163.bugfix @@ -0,0 +1 @@ +Fixed embedded player crash when API returns relative listen URL. (#2163) \ No newline at end of file diff --git a/front/public/embed.html b/front/public/embed.html index 6a3ee100f..2d13aee3b 100644 --- a/front/public/embed.html +++ b/front/public/embed.html @@ -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() }) }