From c7e9152590fa64922e75f24f41529e1a8ffa03a2 Mon Sep 17 00:00:00 2001 From: Kasper Seweryn Date: Thu, 22 Jun 2023 00:34:52 +0200 Subject: [PATCH] fix(embed): standardize `instance` or `b` parameter Part-of: --- front/public/embed.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/front/public/embed.html b/front/public/embed.html index 777d7887e..e717c4dc6 100644 --- a/front/public/embed.html +++ b/front/public/embed.html @@ -20,7 +20,7 @@ // Params const params = new URL(location.href).searchParams - const baseUrl = params.get('instance') ?? params.get('b') ?? '' + let baseUrl = params.get('instance') ?? params.get('b') ?? location.origin const type = params.get('type') const id = params.get('id') @@ -34,6 +34,14 @@ error.value = `The embed widget couldn't read the provided media ID: ${id}.` } + // Standardize base URL + try { + baseUrl = new URL(baseUrl).origin + } catch (err) { + console.error(err) + error.value = `The embed widget couldn't read the provided instance URL: ${baseUrl}.` + } + // Cover const DEFAULT_COVER = '/embed-default-cover.jpeg' const cover = reactive({ value: DEFAULT_COVER })