diff --git a/web/src/lib/components/profile/ProfileEditForm.svelte b/web/src/lib/components/profile/ProfileEditForm.svelte index 3753ddb57..c2f66aae3 100644 --- a/web/src/lib/components/profile/ProfileEditForm.svelte +++ b/web/src/lib/components/profile/ProfileEditForm.svelte @@ -10,7 +10,7 @@ import Input from "$lib/components/ui/Input.svelte"; import Textarea from "$lib/components/ui/Textarea.svelte"; import { getAuth } from "$lib/auth.svelte"; - import { putProfile } from "$lib/api/profile"; + import { putProfile, normalizeProfileLink, type ProfileLink } from "$lib/api/profile"; import type { ProfileRecord } from "$lib/api/records"; import { createAction } from "$lib/action.svelte"; @@ -40,7 +40,9 @@ event.preventDefault(); const agent = auth.agent; if (!agent) return; - const cleanLinks = links.map((link) => link.value.trim()).filter(Boolean); + const cleanLinks = links + .map((link) => normalizeProfileLink(link.value)) + .filter((link): link is ProfileLink => link !== undefined); // put replaces the whole record, so carry unedited fields (avatar, pins, stats). const record: ProfileRecord = { ...profile, @@ -49,12 +51,12 @@ description: description.trim() || undefined, pronouns: pronouns.trim() || undefined, location: location.trim() || undefined, - links: cleanLinks.length > 0 ? (cleanLinks as ProfileRecord["links"]) : undefined + links: cleanLinks.length > 0 ? cleanLinks : undefined }; await putProfile(agent, record); onSaved(record); }, - () => "Could not save profile. Try again." + (cause) => (cause instanceof Error ? cause.message : "Could not save profile. Try again.") ); diff --git a/web/src/routes/settings/profile/avatar/+page.svelte b/web/src/routes/settings/profile/avatar/+page.svelte index 7a58cbfa5..f4cecae5a 100644 --- a/web/src/routes/settings/profile/avatar/+page.svelte +++ b/web/src/routes/settings/profile/avatar/+page.svelte @@ -22,7 +22,7 @@ backLabel="Profile" backHref="/settings" title="Upload or remove avatar" - description="Upload a new image (PNG or JPEG, max 5MB) or remove your current avatar." + description="Upload a new image (PNG or JPEG, max 1MB) or remove your current avatar." > diff --git a/web/src/routes/welcome/+page.svelte b/web/src/routes/welcome/+page.svelte index ab0cc6eef..d68ef6a71 100644 --- a/web/src/routes/welcome/+page.svelte +++ b/web/src/routes/welcome/+page.svelte @@ -5,7 +5,7 @@ import { resolve } from "$app/paths"; import { onDestroy, untrack } from "svelte"; import X from "$icon/x"; - import { uploadProfileAvatar, putProfile } from "$lib/api/profile"; + import { uploadProfileAvatar, putProfile, normalizeProfileLink } from "$lib/api/profile"; import type { ProfileRecord } from "$lib/api/records"; import { createPubKey, deletePubKey, sshFingerprint } from "$lib/api/settings"; import { getAuth } from "$lib/auth.svelte"; @@ -102,17 +102,7 @@ if (!saveDraft) { record = { $type: "sh.tangled.actor.profile", bluesky: false }; } else { - const website = draft.website.trim(); - let firstLink: string | undefined; - if (website) { - const url = new URL( - /^[a-z][a-z\d+.-]*:/i.test(website) ? website : `https://${website}` - ); - if (url.protocol !== "http:" && url.protocol !== "https:") { - throw new Error("Website must use http or https."); - } - firstLink = url.toString(); - } + const firstLink = normalizeProfileLink(draft.website); const remainingLinks = loadedProfile?.links?.slice(1) ?? []; const links = firstLink ? [firstLink, ...remainingLinks] : remainingLinks; const avatar = draft.avatarFile @@ -125,7 +115,7 @@ avatar, description: draft.description.trim() || undefined, pronouns: draft.pronouns.trim() || undefined, - links: links.length > 0 ? (links as ProfileRecord["links"]) : undefined + links: links.length > 0 ? links : undefined }; }