From 4ab1d32f182c7eff673d0620501a737a3d4b5bb3 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Thu, 23 May 2024 20:19:41 -0300 Subject: [PATCH] fix: add 'https' prefix in website --- src/views/mastodon/accounts.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/views/mastodon/accounts.ts b/src/views/mastodon/accounts.ts index f8294d85..7973c2a6 100644 --- a/src/views/mastodon/accounts.ts +++ b/src/views/mastodon/accounts.ts @@ -31,6 +31,23 @@ async function renderAccount( website, } = n.json().pipe(n.metadata()).catch({}).parse(event.content); + let websiteUrl; + try { + // See if 'website' is a valid url + new URL(website); + websiteUrl = website; + } catch (_) { + try { + // 'website' could still be a valid url + // try adding a 'https' prefix to 'website' + new URL('https' + website); + websiteUrl = 'https' + website; + } catch (_) { + // 'website' is not a valid url even with 'https' prefix + websiteUrl = ''; + } + } + const npub = nip19.npubEncode(pubkey); const parsed05 = await parseAndVerifyNip05(nip05, pubkey); const role = event.user?.tags.find(([name]) => name === 'role')?.[1] ?? 'user'; @@ -86,7 +103,7 @@ async function renderAccount( pubkey, lud16, }, - website, + website: websiteUrl, }; }