From 9ab2d8957443967b6c419d13f927e77755401d30 Mon Sep 17 00:00:00 2001 From: LucHeart Date: Wed, 2 Dec 2026 23:08:36 +0100 Subject: [PATCH 1/7] feat: public share custom URLs and public profiles - Custom URL field when creating a public share, and a settings card to edit name, custom URL and expiry - Profile settings page with public toggle, pronouns, bio, socials and default public share - /u/{username} profile page and /u/{username}/{slug} public share pages - Show the author's public profile on public share pages --- e2e/integration/public-profiles.spec.ts | 80 +++ messages/de.json | 8 + messages/en.json | 44 ++ messages/es.json | 8 + messages/et.json | 8 + messages/fi.json | 8 + messages/fr.json | 8 + messages/ja.json | 8 + messages/nb.json | 8 + messages/nl.json | 8 + messages/sv.json | 8 + messages/uk.json | 8 + messages/uwu.json | 8 + messages/zh-Hans.json | 8 + messages/zh-Hant.json | 8 + src/lib/api/internal/generated/index.ts | 37 + src/lib/api/internal/generated/sdk.gen.ts | 218 ++++-- .../internal/generated/transformers.gen.ts | 16 + src/lib/api/internal/generated/types.gen.ts | 642 ++++++++++++------ .../public-share/AuthorProfileCard.svelte | 84 +++ .../public-share}/ControlView.svelte | 38 +- .../public-share/PublicShareView.svelte | 78 +++ .../components/public-share/SlugInput.svelte | 43 ++ src/lib/errorhandling/problemMessages.ts | 14 + src/lib/errorhandling/problemTypes.ts | 17 + src/lib/utils/public-share.test.ts | 28 + src/lib/utils/public-share.ts | 15 + src/lib/utils/slug.test.ts | 21 + src/lib/utils/slug.ts | 15 + src/lib/utils/socials.test.ts | 66 ++ src/lib/utils/socials.ts | 123 ++++ src/routes/(app)/profile/+page.svelte | 334 ++++++++- src/routes/(app)/shares/public/+page.svelte | 5 +- .../public/[shareId=guid]/edit/+page.svelte | 12 +- .../edit/share-settings-card.svelte | 74 ++ .../public/dialog-publicshare-create.svelte | 15 +- .../shares/public/[shareId=guid]/+page.svelte | 68 +- src/routes/u/+layout.ts | 2 + src/routes/u/[username]/+page.svelte | 77 +++ src/routes/u/[username]/[slug]/+page.svelte | 54 ++ 40 files changed, 1981 insertions(+), 343 deletions(-) create mode 100644 e2e/integration/public-profiles.spec.ts create mode 100644 src/lib/components/public-share/AuthorProfileCard.svelte rename src/{routes/shares/public/[shareId=guid] => lib/components/public-share}/ControlView.svelte (81%) create mode 100644 src/lib/components/public-share/PublicShareView.svelte create mode 100644 src/lib/components/public-share/SlugInput.svelte create mode 100644 src/lib/utils/public-share.test.ts create mode 100644 src/lib/utils/public-share.ts create mode 100644 src/lib/utils/slug.test.ts create mode 100644 src/lib/utils/slug.ts create mode 100644 src/lib/utils/socials.test.ts create mode 100644 src/lib/utils/socials.ts create mode 100644 src/routes/(app)/shares/public/[shareId=guid]/edit/share-settings-card.svelte create mode 100644 src/routes/u/+layout.ts create mode 100644 src/routes/u/[username]/+page.svelte create mode 100644 src/routes/u/[username]/[slug]/+page.svelte diff --git a/e2e/integration/public-profiles.spec.ts b/e2e/integration/public-profiles.spec.ts new file mode 100644 index 00000000..c89bc0bb --- /dev/null +++ b/e2e/integration/public-profiles.spec.ts @@ -0,0 +1,80 @@ +import { expect, test } from './lib/test-fixtures'; + +test.describe('public profiles and custom URLs', () => { + test('profile is private by default', async ({ browser, user }) => { + const anon = await browser.newContext(); + const page = await anon.newPage(); + await page.goto(`/u/${user.credentials.username}`); + await expect(page.getByText('Profile not found')).toBeVisible(); + await anon.close(); + }); + + test('custom URL, public profile and default public share', async ({ + authedPage, + browser, + user, + }) => { + const username = user.credentials.username; + const page = authedPage; + + // Create a public share with a custom URL + await page.goto('/shares/public'); + await page.getByRole('main').getByRole('button', { name: 'New Share' }).first().click(); + const dialog = page.getByRole('dialog'); + await dialog.getByLabel('Name').fill('Profile Share'); + await dialog.getByLabel('Custom URL').fill('Bad--Slug'); + await expect(dialog.getByText(/use 2-32 lowercase letters/i)).toBeVisible(); + await expect(dialog.getByRole('button', { name: 'Create' })).toBeDisabled(); + await dialog.getByLabel('Custom URL').fill('Fun-Times'); + await expect(dialog.getByText(`/u/${username}/fun-times`)).toBeVisible(); + await dialog.getByRole('button', { name: 'Create' }).click(); + await expect(page.getByText('Created new public share')).toBeVisible(); + await expect(page.getByRole('main').locator('input[readonly]')).toHaveValue( + new RegExp(`/u/${username}/fun-times$`) + ); + + // Change the custom URL from the edit page + await page.getByRole('heading', { name: 'Profile Share' }).click(); + await expect(page).toHaveURL(/\/shares\/public\/[0-9a-f-]+$/); + await page.goto(`${page.url()}/edit`); + const settings = page.locator('[data-slot="card"]', { hasText: 'Name, custom URL and expiry' }); + await settings.getByLabel('Custom URL').fill('renamed'); + await settings.getByRole('button', { name: 'Save Changes' }).click(); + await expect(page.getByText('Public share updated')).toBeVisible(); + + // Make the profile public with pronouns, bio, a social and the default share + await page.goto('/profile'); + await page.getByRole('switch', { name: /make my profile public/i }).click(); + await page.getByRole('textbox', { name: 'Pronouns' }).fill('they/them'); + await page.getByRole('textbox', { name: 'Bio' }).fill('Hello from the e2e suite'); + await page.getByRole('button', { name: 'Add social' }).click(); + await page.getByPlaceholder('https://example.com').fill('https://example.org/me'); + await page.getByRole('combobox').filter({ hasText: 'None' }).click(); + await page.getByRole('option', { name: 'Profile Share' }).click(); + await page.getByRole('button', { name: 'Save Changes' }).click(); + await expect(page.getByText('Profile saved')).toBeVisible(); + + // Visitors without an account see the profile, the default share and the custom URL + const anon = await browser.newContext(); + const visitor = await anon.newPage(); + + await visitor.goto(`/u/${username}`); + await expect(visitor.getByText('Hello from the e2e suite')).toBeVisible(); + await expect(visitor.getByText('they/them')).toBeVisible(); + await expect(visitor.getByRole('link', { name: /example\.org\/me/ })).toHaveAttribute( + 'href', + 'https://example.org/me' + ); + await expect(visitor.getByRole('heading', { name: 'Profile Share' })).toBeVisible(); + await expect(visitor.getByRole('button', { name: 'Enter as Guest' })).toBeVisible(); + + await visitor.goto(`/u/${username}/renamed`); + await expect(visitor.getByRole('heading', { name: 'Profile Share' })).toBeVisible(); + await expect(visitor.getByText('Hello from the e2e suite')).toBeVisible(); + + await visitor.goto(`/u/${username}/fun-times`); + await expect(visitor.getByText(/its custom URL has changed/i)).toBeVisible(); + + await anon.close(); + }); +}); diff --git a/messages/de.json b/messages/de.json index e5b81100..f1efb63e 100644 --- a/messages/de.json +++ b/messages/de.json @@ -1052,6 +1052,14 @@ "problem_share_link_not_found_title": "Öffentliche Freigabe nicht gefunden", "problem_share_link_shocker_already_in_share_link_title": "Der Shocker ist bereits in dieser öffentlichen Freigabe", "problem_share_link_shocker_not_in_share_link_title": "Der Shocker ist nicht in dieser öffentlichen Freigabe", + "problem_share_link_slug_invalid_title": "Ungültige benutzerdefinierte URL", + "problem_share_link_slug_invalid_desc": "Verwende 2–32 Kleinbuchstaben, Ziffern und einzelne Bindestriche, ohne Bindestrich am Anfang oder Ende.", + "problem_share_link_slug_taken_title": "Du hast bereits eine öffentliche Freigabe mit dieser benutzerdefinierten URL", + "problem_user_profile_not_found_title": "Profil nicht gefunden", + "problem_user_profile_default_public_share_not_found_title": "Standardmäßige öffentliche Freigabe nicht gefunden", + "problem_user_profile_default_public_share_not_found_desc": "Sie ist möglicherweise abgelaufen oder wurde gelöscht.", + "problem_user_profile_social_invalid_title": "Ungültiges soziales Netzwerk", + "problem_user_profile_social_invalid_desc": "Websites benötigen eine vollständige https://-URL, andere Netzwerke nur deinen Benutzernamen.", "problem_shocker_control_no_permission_title": "Du darfst diesen Shocker nicht steuern", "problem_shocker_control_not_found_title": "Shocker nicht gefunden", "problem_shocker_control_paused_title": "Der Shocker ist pausiert", diff --git a/messages/en.json b/messages/en.json index fed88298..188a37e9 100644 --- a/messages/en.json +++ b/messages/en.json @@ -638,6 +638,35 @@ "profile_title": "Profile", "profile_coming_soon": "Profile is coming soon", "profile_coming_soon_desc": "Your public profile is not available yet. Account details live under Settings.", + "profile_subtitle": "Choose what people see on your profile and your public shares.", + "profile_view": "View profile", + "profile_public_title": "Public profile", + "profile_public_desc": "Your profile is private until you turn this on.", + "profile_public_toggle": "Make my profile public", + "profile_public_on_hint": "Anyone can see your profile, and your public shares show your pronouns, bio and socials.", + "profile_public_off_hint": "Only you can see your profile. Your public shares still work through their links.", + "profile_about_title": "About you", + "profile_about_desc": "Shown on your profile and on your public shares.", + "profile_pronouns": "Pronouns", + "profile_pronouns_placeholder": "e.g. they/them", + "profile_too_long": "Must be {{max}} characters or fewer", + "profile_bio": "Bio", + "profile_bio_placeholder": "Tell people a bit about yourself", + "profile_socials": "Socials", + "profile_socials_desc": "Links to your other accounts, up to {{max}}.", + "profile_socials_add": "Add social", + "profile_socials_remove": "Remove social", + "profile_social_website": "Website", + "profile_social_invalid_website": "Enter a full URL starting with https://", + "profile_social_invalid_handle": "Enter just your username, without spaces or links", + "profile_default_share": "Default public share", + "profile_default_share_desc": "Shown on your profile page so visitors can use it right away.", + "profile_default_share_none": "None", + "profile_preview": "Preview", + "profile_toast_saved": "Profile saved", + "public_profile_not_found_title": "Profile not found", + "public_profile_not_found_desc": "This user does not exist or has not made their profile public.", + "public_profile_no_default_share": "{{name}} has not picked a public share to show here yet.", "common_retry": "Retry", "common_never_used": "Never used", @@ -851,6 +880,13 @@ "public_share_view_enter": "Enter", "public_share_view_enter_guest": "Enter as Guest", "public_share_login": "Login", + "public_share_custom_url": "Custom URL", + "public_share_custom_url_optional": "Optional, lowercase letters, numbers and hyphens", + "public_share_slug_invalid": "Use 2-32 lowercase letters, numbers and single hyphens", + "public_share_slug_not_found_desc": "This public share does not exist, or its custom URL has changed.", + "public_share_settings_title": "Settings", + "public_share_settings_desc": "Name, custom URL and expiry of this public share.", + "public_share_toast_settings_saved": "Public share updated", "perm_shock_on": "Shock enabled", "perm_shock_off": "Shock disabled", "perm_vibrate_on": "Vibrate enabled", @@ -1099,6 +1135,14 @@ "problem_share_link_not_found_title": "Public share not found", "problem_share_link_shocker_already_in_share_link_title": "Shocker is already in this public share", "problem_share_link_shocker_not_in_share_link_title": "Shocker is not in this public share", + "problem_share_link_slug_invalid_title": "Invalid custom URL", + "problem_share_link_slug_invalid_desc": "Use 2-32 lowercase letters, numbers and single hyphens, not starting or ending with a hyphen.", + "problem_share_link_slug_taken_title": "You already have a public share with this custom URL", + "problem_user_profile_not_found_title": "Profile not found", + "problem_user_profile_default_public_share_not_found_title": "Default public share not found", + "problem_user_profile_default_public_share_not_found_desc": "It may have expired or been deleted.", + "problem_user_profile_social_invalid_title": "Invalid social", + "problem_user_profile_social_invalid_desc": "Websites need a full https:// URL, other socials just your username.", "problem_shocker_control_no_permission_title": "You do not have permission to control this shocker", "problem_shocker_control_not_found_title": "Shocker not found", "problem_shocker_control_paused_title": "Shocker is paused", diff --git a/messages/es.json b/messages/es.json index f6ef677d..5963ef2f 100644 --- a/messages/es.json +++ b/messages/es.json @@ -1052,6 +1052,14 @@ "problem_share_link_not_found_title": "No se encontró el enlace público", "problem_share_link_shocker_already_in_share_link_title": "El shocker ya está en este enlace público", "problem_share_link_shocker_not_in_share_link_title": "El shocker no está en este enlace público", + "problem_share_link_slug_invalid_title": "URL personalizada no válida", + "problem_share_link_slug_invalid_desc": "Usa de 2 a 32 letras minúsculas, números y guiones simples, sin empezar ni terminar con un guion.", + "problem_share_link_slug_taken_title": "Ya tienes un enlace público con esta URL personalizada", + "problem_user_profile_not_found_title": "No se encontró el perfil", + "problem_user_profile_default_public_share_not_found_title": "No se encontró el enlace público predeterminado", + "problem_user_profile_default_public_share_not_found_desc": "Puede que haya caducado o se haya eliminado.", + "problem_user_profile_social_invalid_title": "Red social no válida", + "problem_user_profile_social_invalid_desc": "Los sitios web necesitan una URL completa con https://; las demás redes, solo tu nombre de usuario.", "problem_shocker_control_no_permission_title": "No tienes permiso para controlar este shocker", "problem_shocker_control_not_found_title": "No se encontró el shocker", "problem_shocker_control_paused_title": "El shocker está en pausa", diff --git a/messages/et.json b/messages/et.json index b4075e5f..4fff8de0 100644 --- a/messages/et.json +++ b/messages/et.json @@ -1052,6 +1052,14 @@ "problem_share_link_not_found_title": "Avalikku jagamist ei leitud", "problem_share_link_shocker_already_in_share_link_title": "Shocker on juba selles avalikus jagamises", "problem_share_link_shocker_not_in_share_link_title": "Shocker pole selles avalikus jagamises", + "problem_share_link_slug_invalid_title": "Vigane kohandatud URL", + "problem_share_link_slug_invalid_desc": "Kasuta 2–32 väiketähte, numbrit ja üksikut sidekriipsu, mis ei alga ega lõppe sidekriipsuga.", + "problem_share_link_slug_taken_title": "Sul on juba selle kohandatud URL-iga avalik jagamine", + "problem_user_profile_not_found_title": "Profiili ei leitud", + "problem_user_profile_default_public_share_not_found_title": "Vaikimisi avalikku jagamist ei leitud", + "problem_user_profile_default_public_share_not_found_desc": "See võib olla aegunud või kustutatud.", + "problem_user_profile_social_invalid_title": "Vigane sotsiaalmeedia konto", + "problem_user_profile_social_invalid_desc": "Veebisaidid vajavad täielikku https:// URL-i, teised kontod ainult sinu kasutajanime.", "problem_shocker_control_no_permission_title": "Sul pole õigust seda shockerit juhtida", "problem_shocker_control_not_found_title": "Shockerit ei leitud", "problem_shocker_control_paused_title": "Shocker on peatatud", diff --git a/messages/fi.json b/messages/fi.json index 83b00122..a2bf0621 100644 --- a/messages/fi.json +++ b/messages/fi.json @@ -1052,6 +1052,14 @@ "problem_share_link_not_found_title": "Julkista jakoa ei löytynyt", "problem_share_link_shocker_already_in_share_link_title": "Shocker on jo tässä julkisessa jaossa", "problem_share_link_shocker_not_in_share_link_title": "Shocker ei ole tässä julkisessa jaossa", + "problem_share_link_slug_invalid_title": "Virheellinen mukautettu URL", + "problem_share_link_slug_invalid_desc": "Käytä 2–32 pientä kirjainta, numeroa ja yksittäistä yhdysmerkkiä, ei yhdysmerkkiä alussa tai lopussa.", + "problem_share_link_slug_taken_title": "Sinulla on jo julkinen jako tällä mukautetulla URL-osoitteella", + "problem_user_profile_not_found_title": "Profiilia ei löytynyt", + "problem_user_profile_default_public_share_not_found_title": "Oletusarvoista julkista jakoa ei löytynyt", + "problem_user_profile_default_public_share_not_found_desc": "Se on voinut vanhentua tai se on poistettu.", + "problem_user_profile_social_invalid_title": "Virheellinen some-tili", + "problem_user_profile_social_invalid_desc": "Verkkosivustot tarvitsevat täyden https://-osoitteen, muut tilit vain käyttäjänimesi.", "problem_shocker_control_no_permission_title": "Sinulla ei ole oikeutta ohjata tätä shockeria", "problem_shocker_control_not_found_title": "Shockeria ei löytynyt", "problem_shocker_control_paused_title": "Shocker on keskeytetty", diff --git a/messages/fr.json b/messages/fr.json index 19f92a7f..0d867da8 100644 --- a/messages/fr.json +++ b/messages/fr.json @@ -1052,6 +1052,14 @@ "problem_share_link_not_found_title": "Partage public introuvable", "problem_share_link_shocker_already_in_share_link_title": "Le shocker est déjà dans ce partage public", "problem_share_link_shocker_not_in_share_link_title": "Le shocker n'est pas dans ce partage public", + "problem_share_link_slug_invalid_title": "URL personnalisée invalide", + "problem_share_link_slug_invalid_desc": "Utilise de 2 à 32 lettres minuscules, chiffres et tirets simples, sans tiret au début ni à la fin.", + "problem_share_link_slug_taken_title": "Tu as déjà un partage public avec cette URL personnalisée", + "problem_user_profile_not_found_title": "Profil introuvable", + "problem_user_profile_default_public_share_not_found_title": "Partage public par défaut introuvable", + "problem_user_profile_default_public_share_not_found_desc": "Il a peut-être expiré ou été supprimé.", + "problem_user_profile_social_invalid_title": "Réseau social invalide", + "problem_user_profile_social_invalid_desc": "Les sites web nécessitent une URL complète en https://, les autres réseaux seulement ton nom d’utilisateur.", "problem_shocker_control_no_permission_title": "Vous n'êtes pas autorisé à contrôler ce shocker", "problem_shocker_control_not_found_title": "Shocker introuvable", "problem_shocker_control_paused_title": "Le shocker est en pause", diff --git a/messages/ja.json b/messages/ja.json index 49fe349e..4a45637a 100644 --- a/messages/ja.json +++ b/messages/ja.json @@ -1047,6 +1047,14 @@ "problem_share_link_not_found_title": "公開共有が見つかりません", "problem_share_link_shocker_already_in_share_link_title": "ショッカーはすでにこの公開共有に含まれています", "problem_share_link_shocker_not_in_share_link_title": "ショッカーはこの公開共有に含まれていません", + "problem_share_link_slug_invalid_title": "カスタムURLが無効です", + "problem_share_link_slug_invalid_desc": "小文字、数字、単一のハイフンを2~32文字で使用してください。先頭と末尾にハイフンは使えません。", + "problem_share_link_slug_taken_title": "このカスタムURLの公開共有はすでにあります", + "problem_user_profile_not_found_title": "プロフィールが見つかりません", + "problem_user_profile_default_public_share_not_found_title": "デフォルトの公開共有が見つかりません", + "problem_user_profile_default_public_share_not_found_desc": "期限切れか、削除された可能性があります。", + "problem_user_profile_social_invalid_title": "SNSが無効です", + "problem_user_profile_social_invalid_desc": "ウェブサイトは https:// から始まる完全なURL、その他のSNSはユーザー名のみを入力してください。", "problem_shocker_control_no_permission_title": "このショッカーを操作する権限がありません", "problem_shocker_control_not_found_title": "ショッカーが見つかりません", "problem_shocker_control_paused_title": "ショッカーは一時停止中です", diff --git a/messages/nb.json b/messages/nb.json index e8db3d28..db6c9ab9 100644 --- a/messages/nb.json +++ b/messages/nb.json @@ -1052,6 +1052,14 @@ "problem_share_link_not_found_title": "Fant ikke delingslenken", "problem_share_link_shocker_already_in_share_link_title": "Denne shockeren deles allerede via lenken", "problem_share_link_shocker_not_in_share_link_title": "Denne shockeren deles ikke via lenken", + "problem_share_link_slug_invalid_title": "Ugyldig egendefinert URL", + "problem_share_link_slug_invalid_desc": "Bruk 2–32 små bokstaver, tall og enkle bindestreker, uten bindestrek først eller sist.", + "problem_share_link_slug_taken_title": "Du har allerede en delingslenke med denne egendefinerte URL-en", + "problem_user_profile_not_found_title": "Fant ikke profilen", + "problem_user_profile_default_public_share_not_found_title": "Fant ikke standard delingslenke", + "problem_user_profile_default_public_share_not_found_desc": "Den kan ha utløpt eller blitt slettet.", + "problem_user_profile_social_invalid_title": "Ugyldig sosial konto", + "problem_user_profile_social_invalid_desc": "Nettsteder trenger en fullstendig https://-URL, andre kontoer bare brukernavnet ditt.", "problem_shocker_control_no_permission_title": "Du har ikke tillatelse til å styre denne shockeren", "problem_shocker_control_not_found_title": "Fant ikke shockeren", "problem_shocker_control_paused_title": "Shockeren er satt på pause", diff --git a/messages/nl.json b/messages/nl.json index 008fd897..491c72e2 100644 --- a/messages/nl.json +++ b/messages/nl.json @@ -1052,6 +1052,14 @@ "problem_share_link_not_found_title": "Openbare deling niet gevonden", "problem_share_link_shocker_already_in_share_link_title": "Shocker zit al in deze openbare deling", "problem_share_link_shocker_not_in_share_link_title": "Shocker zit niet in deze openbare deling", + "problem_share_link_slug_invalid_title": "Ongeldige aangepaste URL", + "problem_share_link_slug_invalid_desc": "Gebruik 2–32 kleine letters, cijfers en enkele koppeltekens, zonder koppelteken aan het begin of eind.", + "problem_share_link_slug_taken_title": "Je hebt al een openbare deling met deze aangepaste URL", + "problem_user_profile_not_found_title": "Profiel niet gevonden", + "problem_user_profile_default_public_share_not_found_title": "Standaard openbare deling niet gevonden", + "problem_user_profile_default_public_share_not_found_desc": "Deze is mogelijk verlopen of verwijderd.", + "problem_user_profile_social_invalid_title": "Ongeldig sociaal account", + "problem_user_profile_social_invalid_desc": "Websites hebben een volledige https://-URL nodig, andere accounts alleen je gebruikersnaam.", "problem_shocker_control_no_permission_title": "Je hebt geen toestemming om deze shocker te bedienen", "problem_shocker_control_not_found_title": "Shocker niet gevonden", "problem_shocker_control_paused_title": "Shocker is gepauzeerd", diff --git a/messages/sv.json b/messages/sv.json index 65926ced..aebe6009 100644 --- a/messages/sv.json +++ b/messages/sv.json @@ -1052,6 +1052,14 @@ "problem_share_link_not_found_title": "Den offentliga delningen hittades inte", "problem_share_link_shocker_already_in_share_link_title": "Shockern finns redan i den här offentliga delningen", "problem_share_link_shocker_not_in_share_link_title": "Shockern finns inte i den här offentliga delningen", + "problem_share_link_slug_invalid_title": "Ogiltig anpassad URL", + "problem_share_link_slug_invalid_desc": "Använd 2–32 små bokstäver, siffror och enstaka bindestreck, utan bindestreck först eller sist.", + "problem_share_link_slug_taken_title": "Du har redan en offentlig delning med den här anpassade URL:en", + "problem_user_profile_not_found_title": "Profilen hittades inte", + "problem_user_profile_default_public_share_not_found_title": "Den förvalda offentliga delningen hittades inte", + "problem_user_profile_default_public_share_not_found_desc": "Den kan ha gått ut eller tagits bort.", + "problem_user_profile_social_invalid_title": "Ogiltigt socialt konto", + "problem_user_profile_social_invalid_desc": "Webbplatser behöver en fullständig https://-URL, andra konton bara ditt användarnamn.", "problem_shocker_control_no_permission_title": "Du har inte behörighet att styra den här shockern", "problem_shocker_control_not_found_title": "Shockern hittades inte", "problem_shocker_control_paused_title": "Shockern är pausad", diff --git a/messages/uk.json b/messages/uk.json index e4342bb7..e4f3ef45 100644 --- a/messages/uk.json +++ b/messages/uk.json @@ -1062,6 +1062,14 @@ "problem_share_link_not_found_title": "Публічне посилання не знайдено", "problem_share_link_shocker_already_in_share_link_title": "Шокер уже є в цьому публічному посиланні", "problem_share_link_shocker_not_in_share_link_title": "Шокера немає в цьому публічному посиланні", + "problem_share_link_slug_invalid_title": "Недійсна власна URL-адреса", + "problem_share_link_slug_invalid_desc": "Використовуйте 2–32 малі літери, цифри та поодинокі дефіси, без дефіса на початку чи в кінці.", + "problem_share_link_slug_taken_title": "У вас уже є публічне посилання з цією власною URL-адресою", + "problem_user_profile_not_found_title": "Профіль не знайдено", + "problem_user_profile_default_public_share_not_found_title": "Публічне посилання за замовчуванням не знайдено", + "problem_user_profile_default_public_share_not_found_desc": "Можливо, термін його дії минув або його видалено.", + "problem_user_profile_social_invalid_title": "Недійсна соцмережа", + "problem_user_profile_social_invalid_desc": "Для вебсайтів потрібна повна URL-адреса з https://, для інших соцмереж — лише ваше ім’я користувача.", "problem_shocker_control_no_permission_title": "У тебе немає дозволу керувати цим шокером", "problem_shocker_control_not_found_title": "Шокер не знайдено", "problem_shocker_control_paused_title": "Шокер призупинено", diff --git a/messages/uwu.json b/messages/uwu.json index b4ac5393..a280e19c 100644 --- a/messages/uwu.json +++ b/messages/uwu.json @@ -1052,6 +1052,14 @@ "problem_share_link_not_found_title": "Couldn't sniff out that public share", "problem_share_link_shocker_already_in_share_link_title": "That zappy fwiend is already here", "problem_share_link_shocker_not_in_share_link_title": "That zappy fwiend isn't in this share", + "problem_share_link_slug_invalid_title": "That custom URL is all wonky", + "problem_share_link_slug_invalid_desc": "Use 2-32 wowercase wetters, numbers and singwe hyphens, no hyphen at the stawt ow end, pwease~", + "problem_share_link_slug_taken_title": "You alweady have a public share with that custom URL", + "problem_user_profile_not_found_title": "Couldn't sniff out that profile", + "problem_user_profile_default_public_share_not_found_title": "Couldn't sniff out your defauwt public share", + "problem_user_profile_default_public_share_not_found_desc": "It might have expiwed ow been deweted.", + "problem_user_profile_social_invalid_title": "That social is all wonky", + "problem_user_profile_social_invalid_desc": "Websites need a fuww https:// URL, othew socials just youw usewname~", "problem_shocker_control_no_permission_title": "You can't boop this zappy fwiend", "problem_shocker_control_not_found_title": "Couldn't sniff out that zappy fwiend", "problem_shocker_control_paused_title": "That zappy fwiend is napping 💤", diff --git a/messages/zh-Hans.json b/messages/zh-Hans.json index 06f59f47..2454b747 100644 --- a/messages/zh-Hans.json +++ b/messages/zh-Hans.json @@ -1047,6 +1047,14 @@ "problem_share_link_not_found_title": "未找到公开共享", "problem_share_link_shocker_already_in_share_link_title": "该电击器已在此公开共享中", "problem_share_link_shocker_not_in_share_link_title": "该电击器不在此公开共享中", + "problem_share_link_slug_invalid_title": "自定义 URL 无效", + "problem_share_link_slug_invalid_desc": "请使用 2–32 个小写字母、数字和单个连字符,且不能以连字符开头或结尾。", + "problem_share_link_slug_taken_title": "你已有使用此自定义 URL 的公开共享", + "problem_user_profile_not_found_title": "未找到个人资料", + "problem_user_profile_default_public_share_not_found_title": "未找到默认公开共享", + "problem_user_profile_default_public_share_not_found_desc": "它可能已过期或已被删除。", + "problem_user_profile_social_invalid_title": "社交账号无效", + "problem_user_profile_social_invalid_desc": "网站需要以 https:// 开头的完整 URL,其他社交账号只需填写用户名。", "problem_shocker_control_no_permission_title": "你无权控制此电击器", "problem_shocker_control_not_found_title": "未找到电击器", "problem_shocker_control_paused_title": "电击器已暂停", diff --git a/messages/zh-Hant.json b/messages/zh-Hant.json index 393252a3..7423708b 100644 --- a/messages/zh-Hant.json +++ b/messages/zh-Hant.json @@ -1047,6 +1047,14 @@ "problem_share_link_not_found_title": "找不到公開分享", "problem_share_link_shocker_already_in_share_link_title": "電擊器已在此公開分享中", "problem_share_link_shocker_not_in_share_link_title": "電擊器不在此公開分享中", + "problem_share_link_slug_invalid_title": "自訂網址無效", + "problem_share_link_slug_invalid_desc": "請使用 2–32 個小寫字母、數字和單一連字號,且不能以連字號開頭或結尾。", + "problem_share_link_slug_taken_title": "你已有使用此自訂網址的公開分享", + "problem_user_profile_not_found_title": "找不到個人檔案", + "problem_user_profile_default_public_share_not_found_title": "找不到預設公開分享", + "problem_user_profile_default_public_share_not_found_desc": "它可能已過期或已被刪除。", + "problem_user_profile_social_invalid_title": "社群帳號無效", + "problem_user_profile_social_invalid_desc": "網站需要以 https:// 開頭的完整網址,其他社群帳號只需填寫使用者名稱。", "problem_shocker_control_no_permission_title": "你沒有控制此電擊器的權限", "problem_shocker_control_not_found_title": "找不到電擊器", "problem_shocker_control_paused_title": "電擊器已暫停", diff --git a/src/lib/api/internal/generated/index.ts b/src/lib/api/internal/generated/index.ts index b95edc35..31703460 100644 --- a/src/lib/api/internal/generated/index.ts +++ b/src/lib/api/internal/generated/index.ts @@ -57,9 +57,11 @@ export { authenticatedAccountChangeUsername, authenticatedAccountDeactivate, authenticatedAccountGetAuditLog, + authenticatedAccountGetProfile, authenticatedAccountGetSelf, authenticatedAccountListOAuthConnections, authenticatedAccountRemoveOAuthConnection, + authenticatedAccountUpdateProfile, deviceGetLiveControlGatewayV2, deviceGetSelf, devicePair, @@ -76,12 +78,15 @@ export { integrationsGetControlStatChanges, publicGetOnlineDevicesStatistics, publicGetPublicShare, + publicGetPublicShareBySlug, + publicGetUserProfile, sessionsDeleteSession, sessionsGetSelfSession, sessionsListSessions, shareLinksAddShocker, shareLinksCreatePublicShare, shareLinksDeletePublicShare, + shareLinksEditPublicShare, shareLinksEditShocker, shareLinksList, shareLinksPauseShocker, @@ -143,6 +148,7 @@ export { PermissionType, RoleType, ShockerModelType, + SocialPlatform, SortDirection, UsernameAvailability, UsernameErrorType, @@ -396,6 +402,9 @@ export { type AuthenticatedAccountGetAuditLogData, type AuthenticatedAccountGetAuditLogResponse, type AuthenticatedAccountGetAuditLogResponses, + type AuthenticatedAccountGetProfileData, + type AuthenticatedAccountGetProfileResponse, + type AuthenticatedAccountGetProfileResponses, type AuthenticatedAccountGetSelfData, type AuthenticatedAccountGetSelfResponse, type AuthenticatedAccountGetSelfResponses, @@ -407,6 +416,11 @@ export { type AuthenticatedAccountRemoveOAuthConnectionErrors, type AuthenticatedAccountRemoveOAuthConnectionResponse, type AuthenticatedAccountRemoveOAuthConnectionResponses, + type AuthenticatedAccountUpdateProfileData, + type AuthenticatedAccountUpdateProfileError, + type AuthenticatedAccountUpdateProfileErrors, + type AuthenticatedAccountUpdateProfileResponse, + type AuthenticatedAccountUpdateProfileResponses, type AutomationTokenDto, type BackendInfoResponse, type BasicUserInfo, @@ -545,6 +559,7 @@ export { type OpenShockProblem, type OtaItem, type OwnPublicShareResponse, + type OwnUserProfileResponse, type OwnerShockerResponse, type PagedResultOfAuditLogEntryResponse, type PagedResultOfLogEntryWithHub, @@ -560,16 +575,31 @@ export { type PublicGetOnlineDevicesStatisticsData, type PublicGetOnlineDevicesStatisticsResponse, type PublicGetOnlineDevicesStatisticsResponses, + type PublicGetPublicShareBySlugData, + type PublicGetPublicShareBySlugError, + type PublicGetPublicShareBySlugErrors, + type PublicGetPublicShareBySlugResponse, + type PublicGetPublicShareBySlugResponses, type PublicGetPublicShareData, type PublicGetPublicShareError, type PublicGetPublicShareErrors, type PublicGetPublicShareResponse, type PublicGetPublicShareResponses, + type PublicGetUserProfileData, + type PublicGetUserProfileError, + type PublicGetUserProfileErrors, + type PublicGetUserProfileResponse, + type PublicGetUserProfileResponses, + type PublicShareAuthor, type PublicShareCreate, type PublicShareDevice, + type PublicShareEdit, type PublicShareEditShocker, type PublicShareResponse, type PublicShareShocker, + type PublicUserProfileDetails, + type PublicUserProfilePublicShare, + type PublicUserProfileResponse, type ReceivedControlStats, type RemoveUserSharesResponse, type ReportTokensRequest, @@ -606,6 +636,11 @@ export { type ShareLinksDeletePublicShareErrors, type ShareLinksDeletePublicShareResponse, type ShareLinksDeletePublicShareResponses, + type ShareLinksEditPublicShareData, + type ShareLinksEditPublicShareError, + type ShareLinksEditPublicShareErrors, + type ShareLinksEditPublicShareResponse, + type ShareLinksEditPublicShareResponses, type ShareLinksEditShockerData, type ShareLinksEditShockerError, type ShareLinksEditShockerErrors, @@ -760,6 +795,8 @@ export { type UserControlStats, type UserNameBlacklistDto, type UserPatchDto, + type UserProfileSocial, + type UserProfileUpdate, type UserSelfResponse, type UserShareInfo, type UserSharesBulkPauseUserShareShockersData, diff --git a/src/lib/api/internal/generated/sdk.gen.ts b/src/lib/api/internal/generated/sdk.gen.ts index aca66270..8aa114c4 100644 --- a/src/lib/api/internal/generated/sdk.gen.ts +++ b/src/lib/api/internal/generated/sdk.gen.ts @@ -26,9 +26,11 @@ import { devicesOtaGetOtaUpdateHistoryResponseTransformer, integrationsGetControlStatChangesResponseTransformer, publicGetOnlineDevicesStatisticsResponseTransformer, + publicGetPublicShareBySlugResponseTransformer, publicGetPublicShareResponseTransformer, sessionsGetSelfSessionResponseTransformer, sessionsListSessionsResponseTransformer, + shareLinksEditPublicShareResponseTransformer, shareLinksListResponseTransformer, shockerGetAllShockerLogsResponseTransformer, shockerGetShockerByIdResponseTransformer, @@ -207,6 +209,8 @@ import type { AuthenticatedAccountDeactivateResponses, AuthenticatedAccountGetAuditLogData, AuthenticatedAccountGetAuditLogResponses, + AuthenticatedAccountGetProfileData, + AuthenticatedAccountGetProfileResponses, AuthenticatedAccountGetSelfData, AuthenticatedAccountGetSelfResponses, AuthenticatedAccountListOAuthConnectionsData, @@ -214,6 +218,9 @@ import type { AuthenticatedAccountRemoveOAuthConnectionData, AuthenticatedAccountRemoveOAuthConnectionErrors, AuthenticatedAccountRemoveOAuthConnectionResponses, + AuthenticatedAccountUpdateProfileData, + AuthenticatedAccountUpdateProfileErrors, + AuthenticatedAccountUpdateProfileResponses, DeviceGetLiveControlGatewayV2Data, DeviceGetLiveControlGatewayV2Errors, DeviceGetLiveControlGatewayV2Responses, @@ -255,9 +262,15 @@ import type { IntegrationsGetControlStatChangesResponses, PublicGetOnlineDevicesStatisticsData, PublicGetOnlineDevicesStatisticsResponses, + PublicGetPublicShareBySlugData, + PublicGetPublicShareBySlugErrors, + PublicGetPublicShareBySlugResponses, PublicGetPublicShareData, PublicGetPublicShareErrors, PublicGetPublicShareResponses, + PublicGetUserProfileData, + PublicGetUserProfileErrors, + PublicGetUserProfileResponses, SessionsDeleteSessionData, SessionsDeleteSessionErrors, SessionsDeleteSessionResponses, @@ -274,6 +287,9 @@ import type { ShareLinksDeletePublicShareData, ShareLinksDeletePublicShareErrors, ShareLinksDeletePublicShareResponses, + ShareLinksEditPublicShareData, + ShareLinksEditPublicShareErrors, + ShareLinksEditPublicShareResponses, ShareLinksEditShockerData, ShareLinksEditShockerErrors, ShareLinksEditShockerResponses, @@ -1342,6 +1358,33 @@ export const shareLinksDeletePublicShare = ...options, }); +/** + * Edit the name, expiry and slug of a public share + */ +export const shareLinksEditPublicShare = ( + options: Options +): RequestResult< + ShareLinksEditPublicShareResponses, + ShareLinksEditPublicShareErrors, + ThrowOnError, + 'data' +> => + (options.client ?? client).put< + ShareLinksEditPublicShareResponses, + ShareLinksEditPublicShareErrors, + ThrowOnError, + 'data' + >({ + responseTransformer: shareLinksEditPublicShareResponseTransformer, + responseStyle: 'data', + url: '/1/shares/links/{publicShareId}', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers, + }, + }); + /** * Pause a shocker in a public share */ @@ -1428,6 +1471,23 @@ export const publicGetOnlineDevicesStatistics = ( + options: Options +): RequestResult => + (options.client ?? client).get< + PublicGetUserProfileResponses, + PublicGetUserProfileErrors, + ThrowOnError, + 'data' + >({ + responseStyle: 'data', + url: '/1/public/users/{username}', + ...options, + }); + /** * Gets information about a public share. */ @@ -1446,6 +1506,29 @@ export const publicGetPublicShare = ( ...options, }); +/** + * Gets information about a public share by its owner's username and custom slug. + */ +export const publicGetPublicShareBySlug = ( + options: Options +): RequestResult< + PublicGetPublicShareBySlugResponses, + PublicGetPublicShareBySlugErrors, + ThrowOnError, + 'data' +> => + (options.client ?? client).get< + PublicGetPublicShareBySlugResponses, + PublicGetPublicShareBySlugErrors, + ThrowOnError, + 'data' + >({ + responseTransformer: publicGetPublicShareBySlugResponseTransformer, + responseStyle: 'data', + url: '/1/public/shares/links/by-slug/{username}/{slug}', + ...options, + }); + /** * Lets a service holding many users keep their lifetime control stats in sync with a single call per tick. * Returns the lifetime totals of every requested user whose stats changed since the given cursor. @@ -1478,6 +1561,52 @@ export const integrationsGetControlStatChanges = ( + options?: Options +): RequestResult< + DeviceGetLiveControlGatewayV2Responses, + DeviceGetLiveControlGatewayV2Errors, + ThrowOnError, + 'data' +> => + (options?.client ?? client).get< + DeviceGetLiveControlGatewayV2Responses, + DeviceGetLiveControlGatewayV2Errors, + ThrowOnError, + 'data' + >({ + responseStyle: 'data', + url: '/2/device/assignLCG', + ...options, + }); + +/** + * Gets information about the authenticated device. + */ +export const deviceGetSelf = ( + options?: Options +): RequestResult => + (options?.client ?? client).get({ + responseStyle: 'data', + url: '/1/device/self', + ...options, + }); + +/** + * Pair a device with a pair code. + */ +export const devicePair = ( + options: Options +): RequestResult => + (options.client ?? client).get({ + responseStyle: 'data', + url: '/1/device/pair/{pairCode}', + ...options, + }); + /** * Gets the OTA update history for a device */ @@ -1666,52 +1795,6 @@ export const devicesGetShockers = ( ...options, }); -/** - * Gets the best suited LCG node for the client - */ -export const deviceGetLiveControlGatewayV2 = ( - options?: Options -): RequestResult< - DeviceGetLiveControlGatewayV2Responses, - DeviceGetLiveControlGatewayV2Errors, - ThrowOnError, - 'data' -> => - (options?.client ?? client).get< - DeviceGetLiveControlGatewayV2Responses, - DeviceGetLiveControlGatewayV2Errors, - ThrowOnError, - 'data' - >({ - responseStyle: 'data', - url: '/2/device/assignLCG', - ...options, - }); - -/** - * Gets information about the authenticated device. - */ -export const deviceGetSelf = ( - options?: Options -): RequestResult => - (options?.client ?? client).get({ - responseStyle: 'data', - url: '/1/device/self', - ...options, - }); - -/** - * Pair a device with a pair code. - */ -export const devicePair = ( - options: Options -): RequestResult => - (options.client ?? client).get({ - responseStyle: 'data', - url: '/1/device/pair/{pairCode}', - ...options, - }); - /** * Lists all automation tokens */ @@ -2965,3 +3048,46 @@ export const authenticatedAccountListOAuthConnections = ( + options?: Options +): RequestResult => + (options?.client ?? client).get< + AuthenticatedAccountGetProfileResponses, + unknown, + ThrowOnError, + 'data' + >({ + responseStyle: 'data', + url: '/1/account/profile', + ...options, + }); + +/** + * Update the current user's profile settings + */ +export const authenticatedAccountUpdateProfile = ( + options: Options +): RequestResult< + AuthenticatedAccountUpdateProfileResponses, + AuthenticatedAccountUpdateProfileErrors, + ThrowOnError, + 'data' +> => + (options.client ?? client).put< + AuthenticatedAccountUpdateProfileResponses, + AuthenticatedAccountUpdateProfileErrors, + ThrowOnError, + 'data' + >({ + responseStyle: 'data', + url: '/1/account/profile', + ...options, + headers: { + 'Content-Type': 'application/json', + ...options.headers, + }, + }); diff --git a/src/lib/api/internal/generated/transformers.gen.ts b/src/lib/api/internal/generated/transformers.gen.ts index 3ccc9ba6..09419260 100644 --- a/src/lib/api/internal/generated/transformers.gen.ts +++ b/src/lib/api/internal/generated/transformers.gen.ts @@ -26,9 +26,11 @@ import type { DevicesOtaGetOtaUpdateHistoryResponse, IntegrationsGetControlStatChangesResponse, PublicGetOnlineDevicesStatisticsResponse, + PublicGetPublicShareBySlugResponse, PublicGetPublicShareResponse, SessionsGetSelfSessionResponse, SessionsListSessionsResponse, + ShareLinksEditPublicShareResponse, ShareLinksListResponse, ShockerGetAllShockerLogsResponse, ShockerGetShockerByIdResponse, @@ -353,6 +355,13 @@ export const shareLinksListResponseTransformer = async ( return data; }; +export const shareLinksEditPublicShareResponseTransformer = async ( + data: any +): Promise => { + data = ownPublicShareResponseSchemaResponseTransformer(data); + return data; +}; + const loginSessionResponseSchemaResponseTransformer = (data: any) => { data.created = Temporal.Instant.from(data.created); data.expires = Temporal.Instant.from(data.expires); @@ -413,6 +422,13 @@ export const publicGetPublicShareResponseTransformer = async ( return data; }; +export const publicGetPublicShareBySlugResponseTransformer = async ( + data: any +): Promise => { + data = legacyDataResponseOfPublicShareResponseSchemaResponseTransformer(data); + return data; +}; + const userControlStatTotalsSchemaResponseTransformer = (data: any) => { data.received = data.received.map((item: any) => controlStatTotalsSchemaResponseTransformer(item) diff --git a/src/lib/api/internal/generated/types.gen.ts b/src/lib/api/internal/generated/types.gen.ts index a813583d..7a51a49e 100644 --- a/src/lib/api/internal/generated/types.gen.ts +++ b/src/lib/api/internal/generated/types.gen.ts @@ -84,6 +84,28 @@ export type AdminOnlineGatewayResponse = { connectedHubs: number; }; +export type AdminUsersView = { + id: string; + name: string; + email: string; + passwordHashType: null | PasswordHashingAlgorithm; + roles: Array; + createdAt: Temporal.Instant; + activatedAt: null | Temporal.Instant; + createdByAutomationTokenId: null | string; + deactivatedAt: null | Temporal.Instant; + deactivatedByUserId: null | string; + apiTokenCount: number; + passwordResetCount: number; + shockerUserShareCount: number; + shockerPublicShareCount: number; + emailChangeRequestCount: number; + nameChangeRequestCount: number; + deviceCount: number; + shockerCount: number; + shockerControlLogCount: number; +}; + export type AdminUserView = { id: string; name: string; @@ -166,28 +188,6 @@ export type AdminUserViewUserRef = { name: string; }; -export type AdminUsersView = { - id: string; - name: string; - email: string; - passwordHashType: null | PasswordHashingAlgorithm; - roles: Array; - createdAt: Temporal.Instant; - activatedAt: null | Temporal.Instant; - createdByAutomationTokenId: null | string; - deactivatedAt: null | Temporal.Instant; - deactivatedByUserId: null | string; - apiTokenCount: number; - passwordResetCount: number; - shockerUserShareCount: number; - shockerPublicShareCount: number; - emailChangeRequestCount: number; - nameChangeRequestCount: number; - deviceCount: number; - shockerCount: number; - shockerControlLogCount: number; -}; - export const AuditAction = { Login: 'Login', Logout: 'Logout', @@ -337,17 +337,17 @@ export type AuditMetadataAutomationTokenUsedMetadata = { flow: string; }; -export type AuditMetadataEmailChangeRequestedMetadata = { - t?: 'emailChangeRequested'; - newEmail: string; -}; - export type AuditMetadataEmailChangedMetadata = { t?: 'emailChanged'; old: string; new: string; }; +export type AuditMetadataEmailChangeRequestedMetadata = { + t?: 'emailChangeRequested'; + newEmail: string; +}; + export type AuditMetadataLoginMetadata = { t?: 'login'; sessionId: string; @@ -577,6 +577,17 @@ export type ControlStatChangesResponse = { users: Array; }; +export type ControlStatsResponse = { + /** + * Activity on shockers you own. + */ + received: ReceivedControlStats; + /** + * Activity you sent to shockers, your own included. + */ + given: GivenControlStats; +}; + /** * Aggregated activity of one control type, split by whether it was live control. */ @@ -595,17 +606,6 @@ export type ControlStatTotals = { maxIntensity: number; }; -export type ControlStatsResponse = { - /** - * Activity on shockers you own. - */ - received: ReceivedControlStats; - /** - * Activity you sent to shockers, your own included. - */ - given: GivenControlStats; -}; - export const ControlType = { Stop: 'Stop', Shock: 'Shock', @@ -626,6 +626,17 @@ export type CreateAutomationTokenDto = { autoCleanupAfter?: null | string; }; +export type CreatedAutomationTokenDto = { + id: string; + name: string; + secret: string; + types: Array; + createdAt: Temporal.Instant; + lastRotatedAt?: null | Temporal.Instant; + autoCleanupUsers?: boolean; + autoCleanupAfter?: null | string; +}; + export type CreateShareRequest = { shockers: Array; user?: null | string; @@ -641,17 +652,6 @@ export type CreateTokenRequestV2 = { shockerControl: ShockerControlSettings; }; -export type CreatedAutomationTokenDto = { - id: string; - name: string; - secret: string; - types: Array; - createdAt: Temporal.Instant; - lastRotatedAt?: null | Temporal.Instant; - autoCleanupUsers?: boolean; - autoCleanupAfter?: null | string; -}; - export type DailyControlStats = { /** * Day in the requested time zone. @@ -876,14 +876,14 @@ export type LegacyDataResponseOfArrayOfLogEntry = { data: Array; }; -export type LegacyDataResponseOfArrayOfOwnPublicShareResponse = { +export type LegacyDataResponseOfArrayOfOwnerShockerResponse = { message: string; - data: Array; + data: Array; }; -export type LegacyDataResponseOfArrayOfOwnerShockerResponse = { +export type LegacyDataResponseOfArrayOfOwnPublicShareResponse = { message: string; - data: Array; + data: Array; }; export type LegacyDataResponseOfArrayOfShareCodeInfo = { @@ -906,6 +906,11 @@ export type LegacyDataResponseOfBackendInfoResponse = { data: BackendInfoResponse; }; +export type LegacyDataResponseOfboolean = { + message: string; + data: boolean; +}; + export type LegacyDataResponseOfDeviceSelfResponse = { message: string; data: DeviceSelfResponse; @@ -968,11 +973,6 @@ export type LegacyDataResponseOfStatsResponse = { data: StatsResponse; }; -export type LegacyDataResponseOfboolean = { - message: string; - data: boolean; -}; - export type LegacyDataResponseOfstring = { message: string; data: string; @@ -1115,18 +1115,27 @@ export const OtaUpdateStatus = { export type OtaUpdateStatus = (typeof OtaUpdateStatus)[keyof typeof OtaUpdateStatus]; +export type OwnerShockerResponse = { + id: string; + name: string; + image: string; + devices: Array; +}; + export type OwnPublicShareResponse = { id: string; name: string; + slug: null | string; createdOn: Temporal.Instant; expiresOn?: null | Temporal.Instant; }; -export type OwnerShockerResponse = { - id: string; - name: string; - image: string; - devices: Array; +export type OwnUserProfileResponse = { + isPublic: boolean; + pronouns: null | string; + bio: null | string; + socials: Array; + defaultPublicShareId: null | string; }; /** @@ -1258,9 +1267,20 @@ export type ProblemDetails = { instance?: null | string; }; +export type PublicShareAuthor = { + id: string; + name: string; + image: string; + profile: null | PublicUserProfileDetails; +}; + export type PublicShareCreate = { name: string; expiresOn?: null | Temporal.Instant; + /** + * Custom URL segment, reachable at /u/{username}/{slug}. Unique per owner. + */ + slug?: null | string; }; export type PublicShareDevice = { @@ -1269,6 +1289,15 @@ export type PublicShareDevice = { shockers: Array; }; +/** + * Replaces all editable fields of a public share, null clears the expiry or slug. + */ +export type PublicShareEdit = { + name: string; + expiresOn: null | Temporal.Instant; + slug: null | string; +}; + export type PublicShareEditShocker = { permissions: ShockerPermissions; limits: ShockerLimits; @@ -1278,9 +1307,10 @@ export type PublicShareEditShocker = { export type PublicShareResponse = { id: string; name: string; + slug: null | string; createdOn: Temporal.Instant; expiresOn?: null | Temporal.Instant; - author: BasicUserInfo; + author: PublicShareAuthor; devices?: Array; }; @@ -1304,6 +1334,24 @@ export type PublicShareShocker = { paused: number; }; +export type PublicUserProfileDetails = { + pronouns: null | string; + bio: null | string; + socials: Array; +}; + +export type PublicUserProfilePublicShare = { + id: string; + name: string; + slug: null | string; +}; + +export type PublicUserProfileResponse = { + user: BasicUserInfo; + profile: PublicUserProfileDetails; + defaultPublicShare: null | PublicUserProfilePublicShare; +}; + export type ReceivedControlStats = { totals: Array; shockers: Array; @@ -1372,6 +1420,20 @@ export type ShareCodeInfo = { createdOn: Temporal.Instant; }; +export type SharedDevice = { + id: string; + name: string; + shockers: Array; +}; + +export type SharedShocker = { + id: string; + name: string; + isPaused: boolean; + permissions: ShockerPermissions; + limits: ShockerLimits; +}; + export type ShareInfo = { sharedWith: BasicUserInfo; createdOn: Temporal.Instant; @@ -1388,20 +1450,6 @@ export type ShareInviteBaseDetails = { sharedWith: null | BasicUserInfo; }; -export type SharedDevice = { - id: string; - name: string; - shockers: Array; -}; - -export type SharedShocker = { - id: string; - name: string; - isPaused: boolean; - permissions: ShockerPermissions; - limits: ShockerLimits; -}; - /** * Per-token shocker control configuration: a toggle plus min/max limits for intensity and duration. */ @@ -1437,6 +1485,13 @@ export const ShockerModelType = { export type ShockerModelType = (typeof ShockerModelType)[keyof typeof ShockerModelType]; +export type ShockerPermissions = { + vibrate: boolean; + sound: boolean; + shock: boolean; + live?: boolean; +}; + export type ShockerPermLimitPair = { permissions: ShockerPermissions; limits: ShockerLimits; @@ -1455,13 +1510,6 @@ export type ShockerPermLimitPairWithIdAndName = { limits: ShockerLimits; }; -export type ShockerPermissions = { - vibrate: boolean; - sound: boolean; - shock: boolean; - live?: boolean; -}; - export type ShockerResponse = { name: string; isPaused: boolean; @@ -1492,6 +1540,25 @@ export type SignUpV2 = { turnstileResponse: string; }; +export const SocialPlatform = { + Website: 'Website', + Discord: 'Discord', + X: 'X', + Bluesky: 'Bluesky', + Mastodon: 'Mastodon', + Twitch: 'Twitch', + YouTube: 'YouTube', + Kick: 'Kick', + Reddit: 'Reddit', + Instagram: 'Instagram', + TikTok: 'TikTok', + GitHub: 'GitHub', + Telegram: 'Telegram', + FetLife: 'FetLife', +} as const; + +export type SocialPlatform = (typeof SocialPlatform)[keyof typeof SocialPlatform]; + /** * Sort direction for list endpoints. */ @@ -1534,6 +1601,15 @@ export type TokenResponseV2 = { shockerControl: ShockerControlSettings; }; +export type UserControlStats = { + /** + * Null for guests (public shares). + */ + userId: null | string; + user: null | BasicUserInfo; + stats: Array; +}; + /** * Lifetime totals of one user, the same views as ControlStatsResponse without breakdowns. */ @@ -1549,14 +1625,13 @@ export type UserControlStatTotals = { given: Array; }; -export type UserControlStats = { - /** - * Null for guests (public shares). - */ - userId: null | string; - user: null | BasicUserInfo; - stats: Array; -}; +export const UsernameAvailability = { + Available: 'Available', + Taken: 'Taken', + Invalid: 'Invalid', +} as const; + +export type UsernameAvailability = (typeof UsernameAvailability)[keyof typeof UsernameAvailability]; export type UserNameBlacklistDto = { id: string; @@ -1565,11 +1640,51 @@ export type UserNameBlacklistDto = { createdAt: Temporal.Instant; }; +export type UsernameCheckResponse = { + availability: UsernameAvailability; + error?: null | UsernameError; +}; + +export type UsernameError = { + message: string; + type: UsernameErrorType; +}; + +export const UsernameErrorType = { + TooShort: 'TooShort', + TooLong: 'TooLong', + StartOrEndWithWhitespace: 'StartOrEndWithWhitespace', + ResembleEmail: 'ResembleEmail', + ObnoxiousCharacters: 'ObnoxiousCharacters', + Blacklisted: 'Blacklisted', +} as const; + +export type UsernameErrorType = (typeof UsernameErrorType)[keyof typeof UsernameErrorType]; + export type UserPatchDto = { name?: null | string; email?: null | string; }; +export type UserProfileSocial = { + platform: SocialPlatform; + /** + * An absolute http(s) URL for SocialPlatform.Website, otherwise the handle on that platform. + */ + value: string; +}; + +export type UserProfileUpdate = { + isPublic: boolean; + pronouns?: null | string; + bio?: null | string; + socials?: Array; + /** + * Public share shown on the profile page, must be one of your own unexpired public shares. + */ + defaultPublicShareId?: null | string; +}; + export type UserSelfResponse = { id: string; name: string; @@ -1594,40 +1709,11 @@ export type UserShareInfo = { * - 1: Shocker * - 2: UserShare * - 4: PublicShare - * - * For example, a value of 6 (2 | 4) indicates both 'UserShare' and 'PublicShare' reasons. - */ - paused: number; -}; - -export const UsernameAvailability = { - Available: 'Available', - Taken: 'Taken', - Invalid: 'Invalid', -} as const; - -export type UsernameAvailability = (typeof UsernameAvailability)[keyof typeof UsernameAvailability]; - -export type UsernameCheckResponse = { - availability: UsernameAvailability; - error?: null | UsernameError; -}; - -export type UsernameError = { - message: string; - type: UsernameErrorType; -}; - -export const UsernameErrorType = { - TooShort: 'TooShort', - TooLong: 'TooLong', - StartOrEndWithWhitespace: 'StartOrEndWithWhitespace', - ResembleEmail: 'ResembleEmail', - ObnoxiousCharacters: 'ObnoxiousCharacters', - Blacklisted: 'Blacklisted', -} as const; - -export type UsernameErrorType = (typeof UsernameErrorType)[keyof typeof UsernameErrorType]; + * + * For example, a value of 6 (2 | 4) indicates both 'UserShare' and 'PublicShare' reasons. + */ + paused: number; +}; export type V2UserShares = { outgoing: Array; @@ -2845,6 +2931,10 @@ export type ShareLinksCreatePublicShareData = { }; export type ShareLinksCreatePublicShareErrors = { + /** + * Bad Request + */ + 400: OpenShockProblem; /** * You have reached the maximum number of public shares */ @@ -2893,6 +2983,43 @@ export type ShareLinksDeletePublicShareResponses = { export type ShareLinksDeletePublicShareResponse = ShareLinksDeletePublicShareResponses[keyof ShareLinksDeletePublicShareResponses]; +export type ShareLinksEditPublicShareData = { + body: PublicShareEdit; + path: { + publicShareId: string; + }; + query?: never; + url: '/1/shares/links/{publicShareId}'; +}; + +export type ShareLinksEditPublicShareErrors = { + /** + * Expiry date in the past or invalid slug + */ + 400: OpenShockProblem; + /** + * Public share not found or does not belong to you + */ + 404: OpenShockProblem; + /** + * Slug is already used by another of your public shares + */ + 409: OpenShockProblem; +}; + +export type ShareLinksEditPublicShareError = + ShareLinksEditPublicShareErrors[keyof ShareLinksEditPublicShareErrors]; + +export type ShareLinksEditPublicShareResponses = { + /** + * The updated public share + */ + 200: OwnPublicShareResponse; +}; + +export type ShareLinksEditPublicShareResponse = + ShareLinksEditPublicShareResponses[keyof ShareLinksEditPublicShareResponses]; + export type ShareLinksPauseShockerData = { body: PauseRequest; path: { @@ -3004,6 +3131,35 @@ export type PublicGetOnlineDevicesStatisticsResponses = { export type PublicGetOnlineDevicesStatisticsResponse = PublicGetOnlineDevicesStatisticsResponses[keyof PublicGetOnlineDevicesStatisticsResponses]; +export type PublicGetUserProfileData = { + body?: never; + path: { + username: string; + }; + query?: never; + url: '/1/public/users/{username}'; +}; + +export type PublicGetUserProfileErrors = { + /** + * The user does not exist or their profile is not public. + */ + 404: OpenShockProblem; +}; + +export type PublicGetUserProfileError = + PublicGetUserProfileErrors[keyof PublicGetUserProfileErrors]; + +export type PublicGetUserProfileResponses = { + /** + * The profile was successfully retrieved. + */ + 200: PublicUserProfileResponse; +}; + +export type PublicGetUserProfileResponse = + PublicGetUserProfileResponses[keyof PublicGetUserProfileResponses]; + export type PublicGetPublicShareData = { body?: never; path: { @@ -3033,6 +3189,36 @@ export type PublicGetPublicShareResponses = { export type PublicGetPublicShareResponse = PublicGetPublicShareResponses[keyof PublicGetPublicShareResponses]; +export type PublicGetPublicShareBySlugData = { + body?: never; + path: { + username: string; + slug: string; + }; + query?: never; + url: '/1/public/shares/links/by-slug/{username}/{slug}'; +}; + +export type PublicGetPublicShareBySlugErrors = { + /** + * The public share does not exist. + */ + 404: OpenShockProblem; +}; + +export type PublicGetPublicShareBySlugError = + PublicGetPublicShareBySlugErrors[keyof PublicGetPublicShareBySlugErrors]; + +export type PublicGetPublicShareBySlugResponses = { + /** + * The public share information was successfully retrieved. + */ + 200: LegacyDataResponseOfPublicShareResponse; +}; + +export type PublicGetPublicShareBySlugResponse = + PublicGetPublicShareBySlugResponses[keyof PublicGetPublicShareBySlugResponses]; + export type IntegrationsGetControlStatChangesData = { body: ControlStatChangesRequest; path?: never; @@ -3060,6 +3246,85 @@ export type IntegrationsGetControlStatChangesResponses = { export type IntegrationsGetControlStatChangesResponse = IntegrationsGetControlStatChangesResponses[keyof IntegrationsGetControlStatChangesResponses]; +export type DeviceGetLiveControlGatewayV2Data = { + body?: never; + path?: never; + query?: { + version?: number; + }; + url: '/2/device/assignLCG'; +}; + +export type DeviceGetLiveControlGatewayV2Errors = { + /** + * Bad Request + */ + 400: OpenShockProblem; + /** + * Unable to find suitable LCG node + */ + 503: OpenShockProblem; +}; + +export type DeviceGetLiveControlGatewayV2Error = + DeviceGetLiveControlGatewayV2Errors[keyof DeviceGetLiveControlGatewayV2Errors]; + +export type DeviceGetLiveControlGatewayV2Responses = { + /** + * Successfully assigned LCG node + */ + 200: LcgNodeResponseV2; +}; + +export type DeviceGetLiveControlGatewayV2Response = + DeviceGetLiveControlGatewayV2Responses[keyof DeviceGetLiveControlGatewayV2Responses]; + +export type DeviceGetSelfData = { + body?: never; + path?: never; + query?: never; + url: '/1/device/self'; +}; + +export type DeviceGetSelfResponses = { + /** + * The device information was successfully retrieved. + */ + 200: LegacyDataResponseOfDeviceSelfResponse; +}; + +export type DeviceGetSelfResponse = DeviceGetSelfResponses[keyof DeviceGetSelfResponses]; + +export type DevicePairData = { + body?: never; + path: { + /** + * The pair code to pair with. + */ + pairCode: string; + }; + query?: never; + url: '/1/device/pair/{pairCode}'; +}; + +export type DevicePairErrors = { + /** + * No such pair code exists + */ + 404: OpenShockProblem; +}; + +export type DevicePairError = DevicePairErrors[keyof DevicePairErrors]; + +export type DevicePairResponses = { + /** + * Successfully assigned LCG node + */ + 200: LegacyDataResponseOfstring; +}; + +export type DevicePairResponse = DevicePairResponses[keyof DevicePairResponses]; + export type DevicesOtaGetOtaUpdateHistoryData = { body?: never; path: { @@ -3332,85 +3597,6 @@ export type DevicesGetShockersResponses = { export type DevicesGetShockersResponse = DevicesGetShockersResponses[keyof DevicesGetShockersResponses]; -export type DeviceGetLiveControlGatewayV2Data = { - body?: never; - path?: never; - query?: { - version?: number; - }; - url: '/2/device/assignLCG'; -}; - -export type DeviceGetLiveControlGatewayV2Errors = { - /** - * Bad Request - */ - 400: OpenShockProblem; - /** - * Unable to find suitable LCG node - */ - 503: OpenShockProblem; -}; - -export type DeviceGetLiveControlGatewayV2Error = - DeviceGetLiveControlGatewayV2Errors[keyof DeviceGetLiveControlGatewayV2Errors]; - -export type DeviceGetLiveControlGatewayV2Responses = { - /** - * Successfully assigned LCG node - */ - 200: LcgNodeResponseV2; -}; - -export type DeviceGetLiveControlGatewayV2Response = - DeviceGetLiveControlGatewayV2Responses[keyof DeviceGetLiveControlGatewayV2Responses]; - -export type DeviceGetSelfData = { - body?: never; - path?: never; - query?: never; - url: '/1/device/self'; -}; - -export type DeviceGetSelfResponses = { - /** - * The device information was successfully retrieved. - */ - 200: LegacyDataResponseOfDeviceSelfResponse; -}; - -export type DeviceGetSelfResponse = DeviceGetSelfResponses[keyof DeviceGetSelfResponses]; - -export type DevicePairData = { - body?: never; - path: { - /** - * The pair code to pair with. - */ - pairCode: string; - }; - query?: never; - url: '/1/device/pair/{pairCode}'; -}; - -export type DevicePairErrors = { - /** - * No such pair code exists - */ - 404: OpenShockProblem; -}; - -export type DevicePairError = DevicePairErrors[keyof DevicePairErrors]; - -export type DevicePairResponses = { - /** - * Successfully assigned LCG node - */ - 200: LegacyDataResponseOfstring; -}; - -export type DevicePairResponse = DevicePairResponses[keyof DevicePairResponses]; - export type AdminListAutomationTokensData = { body?: never; path?: never; @@ -5033,3 +5219,47 @@ export type AuthenticatedAccountListOAuthConnectionsResponses = { export type AuthenticatedAccountListOAuthConnectionsResponse = AuthenticatedAccountListOAuthConnectionsResponses[keyof AuthenticatedAccountListOAuthConnectionsResponses]; + +export type AuthenticatedAccountGetProfileData = { + body?: never; + path?: never; + query?: never; + url: '/1/account/profile'; +}; + +export type AuthenticatedAccountGetProfileResponses = { + /** + * The profile settings, defaults when the profile was never set up + */ + 200: OwnUserProfileResponse; +}; + +export type AuthenticatedAccountGetProfileResponse = + AuthenticatedAccountGetProfileResponses[keyof AuthenticatedAccountGetProfileResponses]; + +export type AuthenticatedAccountUpdateProfileData = { + body: UserProfileUpdate; + path?: never; + query?: never; + url: '/1/account/profile'; +}; + +export type AuthenticatedAccountUpdateProfileErrors = { + /** + * Invalid social or default public share + */ + 400: OpenShockProblem; +}; + +export type AuthenticatedAccountUpdateProfileError = + AuthenticatedAccountUpdateProfileErrors[keyof AuthenticatedAccountUpdateProfileErrors]; + +export type AuthenticatedAccountUpdateProfileResponses = { + /** + * The updated profile settings + */ + 200: OwnUserProfileResponse; +}; + +export type AuthenticatedAccountUpdateProfileResponse = + AuthenticatedAccountUpdateProfileResponses[keyof AuthenticatedAccountUpdateProfileResponses]; diff --git a/src/lib/components/public-share/AuthorProfileCard.svelte b/src/lib/components/public-share/AuthorProfileCard.svelte new file mode 100644 index 00000000..f06b192e --- /dev/null +++ b/src/lib/components/public-share/AuthorProfileCard.svelte @@ -0,0 +1,84 @@ + + + + +
+ + + {user.name.charAt(0)} + +
+ {#if href} + + {user.name} + {:else} + {user.name} + {/if} + {#if pronouns} + {pronouns} + {/if} +
+
+ + {#if bio} +

{bio}

+ {/if} + + {#if socials.length > 0} +
    + {#each socials as social, i (i)} + {@const url = socialUrl(social)} + {@const display = socialDisplayValue(social)} +
  • + {#if url} + + + {socialPlatformLabel(social.platform)} + {display} + + + + {:else} + + {/if} +
  • + {/each} +
+ {/if} +
+
diff --git a/src/routes/shares/public/[shareId=guid]/ControlView.svelte b/src/lib/components/public-share/ControlView.svelte similarity index 81% rename from src/routes/shares/public/[shareId=guid]/ControlView.svelte rename to src/lib/components/public-share/ControlView.svelte index 453af704..9d7c1396 100644 --- a/src/routes/shares/public/[shareId=guid]/ControlView.svelte +++ b/src/lib/components/public-share/ControlView.svelte @@ -18,9 +18,8 @@ registerHubShockers, } from '#lib/state/live-control-state.svelte.js'; import { onMount, untrack } from 'svelte'; - import { page } from '$app/state'; import ShareLinkInput from '#lib/components/ShareLinkInput.svelte'; - import { encodeShortGuid } from '#lib/utils/short-guid.js'; + import { profilePath, publicSharePath } from '#lib/utils/public-share.js'; import { Button } from '@openshock/svelte-core/components/ui/button'; import { Pencil } from '@lucide/svelte'; import { userState } from '#lib/state/user-state.svelte.js'; @@ -56,9 +55,10 @@ }); } - const shareId = $derived(page.params.shareId); - - let editUrl = $derived(resolve(`shares/public/${shareId}/edit`)); + let editUrl = $derived(resolve(`shares/public/${shareLinkRoot.id}/edit`)); + let profileUrl = $derived( + shareLinkRoot.author.profile ? resolve(profilePath(shareLinkRoot.author.name)) : undefined + ); // Flatten devices+shockers while keeping the deviceId const flatShockers = $derived( @@ -91,7 +91,9 @@
-

Public Share: {shareLinkRoot.name}

+

+ {m.public_share_edit_title({ name: shareLinkRoot.name })} +

- {#if shareId} - - {/if} +
@@ -114,8 +114,13 @@ - @@ -123,8 +128,15 @@ {shareLinkRoot.author.name.charAt(0)} -

{shareLinkRoot.author.name}

-
+ + {shareLinkRoot.author.name} + {#if shareLinkRoot.author.profile?.pronouns} + + {shareLinkRoot.author.profile.pronouns} + + {/if} + +

{m.common_shared_by()}

diff --git a/src/lib/components/public-share/PublicShareView.svelte b/src/lib/components/public-share/PublicShareView.svelte new file mode 100644 index 00000000..6a770775 --- /dev/null +++ b/src/lib/components/public-share/PublicShareView.svelte @@ -0,0 +1,78 @@ + + +{#if entered} + +{:else} +
+ {#if showAuthorProfile && share.author.profile} + + {/if} + + +

{share.name}

+ {m.public_share_view_desc()} +
+ + {#if enterAsGuestClicked} + + + + + + + {:else} + + + + {/if} + +
+
+{/if} diff --git a/src/lib/components/public-share/SlugInput.svelte b/src/lib/components/public-share/SlugInput.svelte new file mode 100644 index 00000000..8640c547 --- /dev/null +++ b/src/lib/components/public-share/SlugInput.svelte @@ -0,0 +1,43 @@ + + + diff --git a/src/lib/errorhandling/problemMessages.ts b/src/lib/errorhandling/problemMessages.ts index 63103ee3..1531d986 100644 --- a/src/lib/errorhandling/problemMessages.ts +++ b/src/lib/errorhandling/problemMessages.ts @@ -184,6 +184,11 @@ export const ProblemMessages: { 'ShareLink.ShockerNotInShareLink': { title: m.problem_share_link_shocker_not_in_share_link_title, }, + 'ShareLink.SlugInvalid': { + title: m.problem_share_link_slug_invalid_title, + description: m.problem_share_link_slug_invalid_desc, + }, + 'ShareLink.SlugTaken': { title: m.problem_share_link_slug_taken_title }, 'Shocker.Control.NoPermission': { title: m.problem_shocker_control_no_permission_title }, 'Shocker.Control.NotFound': { title: m.problem_shocker_control_not_found_title }, 'Shocker.Control.Paused': { title: m.problem_shocker_control_paused_title }, @@ -196,6 +201,15 @@ export const ProblemMessages: { }, 'User.NotFound': { title: m.problem_user_not_found_title }, 'User.Privileged.DeleteDenied': { title: m.problem_user_privileged_delete_denied_title }, + 'UserProfile.DefaultPublicShareNotFound': { + title: m.problem_user_profile_default_public_share_not_found_title, + description: m.problem_user_profile_default_public_share_not_found_desc, + }, + 'UserProfile.NotFound': { title: m.problem_user_profile_not_found_title }, + 'UserProfile.SocialInvalid': { + title: m.problem_user_profile_social_invalid_title, + description: m.problem_user_profile_social_invalid_desc, + }, 'Validation.Error': { title: m.problem_validation_error_title }, 'Webhook.NotFound': { title: m.problem_webhook_not_found_title }, 'Webhook.Unsupported': { diff --git a/src/lib/errorhandling/problemTypes.ts b/src/lib/errorhandling/problemTypes.ts index d7dcde6e..5dc0a735 100644 --- a/src/lib/errorhandling/problemTypes.ts +++ b/src/lib/errorhandling/problemTypes.ts @@ -198,6 +198,12 @@ export const ProblemTypes = { 'ShareLink.NotFound': { title: 'Public share not found' }, 'ShareLink.ShockerAlreadyInShareLink': { title: 'Shocker is already in this public share' }, 'ShareLink.ShockerNotInShareLink': { title: 'Shocker is not in this public share' }, + 'ShareLink.SlugInvalid': { + title: 'Invalid custom URL', + description: + 'Use 2-32 lowercase letters, numbers and single hyphens, not starting or ending with a hyphen.', + }, + 'ShareLink.SlugTaken': { title: 'You already have a public share with this custom URL' }, // Shockers 'Shocker.Control.NoPermission': { title: 'You do not have permission to control this shocker' }, @@ -217,6 +223,17 @@ export const ProblemTypes = { 'User.NotFound': { title: 'User not found' }, 'User.Privileged.DeleteDenied': { title: 'Privileged users cannot be deleted' }, + // User profiles + 'UserProfile.DefaultPublicShareNotFound': { + title: 'Default public share not found', + description: 'It may have expired or been deleted.', + }, + 'UserProfile.NotFound': { title: 'Profile not found' }, + 'UserProfile.SocialInvalid': { + title: 'Invalid social', + description: 'Websites need a full https:// URL, other socials just your username.', + }, + 'Validation.Error': { title: 'Some fields are invalid' }, // Admin webhooks diff --git a/src/lib/utils/public-share.test.ts b/src/lib/utils/public-share.test.ts new file mode 100644 index 00000000..4a9dfdf7 --- /dev/null +++ b/src/lib/utils/public-share.test.ts @@ -0,0 +1,28 @@ +import { describe, expect, it } from 'vitest'; +import { profilePath, publicSharePath } from './public-share'; +import { encodeShortGuid } from './short-guid'; + +const id = '01936b2e-6f1c-7a3e-9b2d-4c5e6f708192'; + +describe('publicSharePath', () => { + it('uses the custom URL when there is a slug', () => { + expect(publicSharePath({ id, slug: 'fun', author: { name: 'Luc' } })).toBe('u/Luc/fun'); + }); + + it('prefers the explicit owner name', () => { + expect(publicSharePath({ id, slug: 'fun' }, 'some one')).toBe('u/some%20one/fun'); + }); + + it('falls back to the short link', () => { + expect(publicSharePath({ id, slug: null, author: { name: 'Luc' } })).toBe( + `s/${encodeShortGuid(id)}` + ); + expect(publicSharePath({ id, slug: 'fun' })).toBe(`s/${encodeShortGuid(id)}`); + }); +}); + +describe('profilePath', () => { + it('encodes the username', () => { + expect(profilePath('a/b')).toBe('u/a%2Fb'); + }); +}); diff --git a/src/lib/utils/public-share.ts b/src/lib/utils/public-share.ts new file mode 100644 index 00000000..c08844a1 --- /dev/null +++ b/src/lib/utils/public-share.ts @@ -0,0 +1,15 @@ +import { encodeShortGuid } from './short-guid'; + +/** Path of a public share: the custom URL when it has a slug, the short GUID link otherwise. */ +export function publicSharePath( + share: { id: string; slug?: string | null; author?: { name: string } }, + ownerName?: string +): `u/${string}/${string}` | `s/${string}` { + const owner = ownerName ?? share.author?.name; + if (share.slug && owner) return `u/${encodeURIComponent(owner)}/${share.slug}`; + return `s/${encodeShortGuid(share.id)}`; +} + +export function profilePath(username: string): `u/${string}` { + return `u/${encodeURIComponent(username)}`; +} diff --git a/src/lib/utils/slug.test.ts b/src/lib/utils/slug.test.ts new file mode 100644 index 00000000..990e49d8 --- /dev/null +++ b/src/lib/utils/slug.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from 'vitest'; +import { isValidSlug, normalizeSlug } from './slug'; + +describe('isValidSlug', () => { + it.each(['ab', 'fun', 'fun-times', 'a1-b2-c3', 'x'.repeat(32)])('accepts %s', (slug) => { + expect(isValidSlug(slug)).toBe(true); + }); + + it.each(['', 'a', '-ab', 'ab-', 'a--b', 'Ab', 'with space', 'émoji', 'x'.repeat(33)])( + 'rejects %s', + (slug) => { + expect(isValidSlug(slug)).toBe(false); + } + ); +}); + +describe('normalizeSlug', () => { + it('trims and lowercases', () => { + expect(normalizeSlug(' Fun-Times ')).toBe('fun-times'); + }); +}); diff --git a/src/lib/utils/slug.ts b/src/lib/utils/slug.ts new file mode 100644 index 00000000..84506988 --- /dev/null +++ b/src/lib/utils/slug.ts @@ -0,0 +1,15 @@ +// Mirrors the backend's SlugValidator and ApiHardLimits.PublicShareSlug*Length. +export const SLUG_MIN_LENGTH = 2; +export const SLUG_MAX_LENGTH = 32; + +const SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/; + +export function normalizeSlug(value: string): string { + return value.trim().toLowerCase(); +} + +export function isValidSlug(slug: string): boolean { + return ( + slug.length >= SLUG_MIN_LENGTH && slug.length <= SLUG_MAX_LENGTH && SLUG_PATTERN.test(slug) + ); +} diff --git a/src/lib/utils/socials.test.ts b/src/lib/utils/socials.test.ts new file mode 100644 index 00000000..cdbbd309 --- /dev/null +++ b/src/lib/utils/socials.test.ts @@ -0,0 +1,66 @@ +import { SocialPlatform } from '#lib/api/index.js'; +import { describe, expect, it } from 'vitest'; +import { isValidSocialValue, socialDisplayValue, socialUrl } from './socials'; + +describe('socialUrl', () => { + it.each([ + [SocialPlatform.X, '@someone', 'https://x.com/someone'], + [SocialPlatform.Bluesky, 'someone.bsky.social', 'https://bsky.app/profile/someone.bsky.social'], + [SocialPlatform.YouTube, '@channel', 'https://www.youtube.com/@channel'], + [SocialPlatform.Reddit, 'u/someone', 'https://www.reddit.com/user/someone'], + [SocialPlatform.TikTok, 'someone', 'https://www.tiktok.com/@someone'], + [SocialPlatform.Mastodon, '@user@mastodon.social', 'https://mastodon.social/@user'], + [SocialPlatform.Website, 'https://example.org/me', 'https://example.org/me'], + ])('%s %s -> %s', (platform, value, expected) => { + expect(socialUrl({ platform, value })).toBe(expected); + }); + + it('has no link for platforms without handle URLs', () => { + expect(socialUrl({ platform: SocialPlatform.Discord, value: 'someone' })).toBeNull(); + expect(socialUrl({ platform: SocialPlatform.FetLife, value: 'someone' })).toBeNull(); + }); + + it('never links non-http websites', () => { + expect( + socialUrl({ platform: SocialPlatform.Website, value: 'javascript:alert(1)' }) + ).toBeNull(); + }); + + it('encodes handles', () => { + expect(socialUrl({ platform: SocialPlatform.GitHub, value: 'a?b#c' })).toBe( + 'https://github.com/a%3Fb%23c' + ); + }); + + it('rejects malformed mastodon handles', () => { + expect(socialUrl({ platform: SocialPlatform.Mastodon, value: 'justuser' })).toBeNull(); + }); +}); + +describe('socialDisplayValue', () => { + it('prefixes handles with @ once', () => { + expect(socialDisplayValue({ platform: SocialPlatform.X, value: '@someone' })).toBe('@someone'); + expect(socialDisplayValue({ platform: SocialPlatform.X, value: 'someone' })).toBe('@someone'); + }); + + it('shows websites without the scheme', () => { + expect( + socialDisplayValue({ platform: SocialPlatform.Website, value: 'https://example.org/me/' }) + ).toBe('example.org/me'); + }); +}); + +describe('isValidSocialValue', () => { + it.each([ + [SocialPlatform.Website, 'https://example.org', true], + [SocialPlatform.Website, 'example.org', false], + [SocialPlatform.Website, 'javascript:alert(1)', false], + [SocialPlatform.Discord, 'someone', true], + [SocialPlatform.Discord, 'has space', false], + [SocialPlatform.X, 'https://x.com/someone', false], + [SocialPlatform.Mastodon, '@user@mastodon.social', true], + [SocialPlatform.X, '', false], + ])('%s %s -> %s', (platform, value, expected) => { + expect(isValidSocialValue(platform, value)).toBe(expected); + }); +}); diff --git a/src/lib/utils/socials.ts b/src/lib/utils/socials.ts new file mode 100644 index 00000000..9f30c711 --- /dev/null +++ b/src/lib/utils/socials.ts @@ -0,0 +1,123 @@ +import { SocialPlatform, type UserProfileSocial } from '#lib/api/index.js'; +import { m } from '#lib/paraglide/messages.js'; + +export const MAX_SOCIALS = 10; +export const SOCIAL_VALUE_MAX_LENGTH = 256; + +export const socialPlatforms = Object.values(SocialPlatform) as SocialPlatform[]; + +const brandNames: Record, string> = { + Discord: 'Discord', + X: 'X', + Bluesky: 'Bluesky', + Mastodon: 'Mastodon', + Twitch: 'Twitch', + YouTube: 'YouTube', + Kick: 'Kick', + Reddit: 'Reddit', + Instagram: 'Instagram', + TikTok: 'TikTok', + GitHub: 'GitHub', + Telegram: 'Telegram', + FetLife: 'FetLife', +}; + +export function socialPlatformLabel(platform: SocialPlatform): string { + return platform === SocialPlatform.Website ? m.profile_social_website() : brandNames[platform]; +} + +export const socialPlaceholders: Record = { + Website: 'https://example.com', + Discord: 'username', + X: 'username', + Bluesky: 'name.bsky.social', + Mastodon: '@user@instance.social', + Twitch: 'username', + YouTube: '@channel', + Kick: 'username', + Reddit: 'username', + Instagram: 'username', + TikTok: 'username', + GitHub: 'username', + Telegram: 'username', + FetLife: 'username', +}; + +const handleProfileUrls: Partial string>> = { + X: (h) => `https://x.com/${h}`, + Bluesky: (h) => `https://bsky.app/profile/${h}`, + Twitch: (h) => `https://www.twitch.tv/${h}`, + YouTube: (h) => `https://www.youtube.com/@${h}`, + Kick: (h) => `https://kick.com/${h}`, + Reddit: (h) => `https://www.reddit.com/user/${h}`, + Instagram: (h) => `https://www.instagram.com/${h}`, + TikTok: (h) => `https://www.tiktok.com/@${h}`, + GitHub: (h) => `https://github.com/${h}`, + Telegram: (h) => `https://t.me/${h}`, +}; + +const MASTODON_HANDLE = /^@?([^@\s/]+)@([a-z0-9-]+(?:\.[a-z0-9-]+)+)$/i; + +/** Strips a leading `@`, and Reddit's `u/` prefix. */ +function cleanHandle(platform: SocialPlatform, value: string): string { + let handle = value.trim().replace(/^@/, ''); + if (platform === SocialPlatform.Reddit) handle = handle.replace(/^u\//i, ''); + return handle; +} + +/** The text shown for a social, e.g. `@name` for handles or the host for websites. */ +export function socialDisplayValue(social: UserProfileSocial): string { + if (social.platform === SocialPlatform.Website) { + try { + const url = new URL(social.value); + return url.host + url.pathname.replace(/\/+$/, ''); + } catch { + return social.value; + } + } + if (social.platform === SocialPlatform.Mastodon) return social.value; + return `@${cleanHandle(social.platform, social.value)}`; +} + +/** + * The profile URL for a social, or null when the platform has no stable handle-based URL + * (Discord, FetLife) or the value is not usable. Only ever returns http(s) URLs. + */ +export function socialUrl(social: UserProfileSocial): string | null { + if (social.platform === SocialPlatform.Website) { + try { + const url = new URL(social.value); + return url.protocol === 'https:' || url.protocol === 'http:' ? url.href : null; + } catch { + return null; + } + } + + if (social.platform === SocialPlatform.Mastodon) { + const match = MASTODON_HANDLE.exec(social.value.trim()); + if (!match) return null; + return `https://${match[2]}/@${encodeURIComponent(match[1])}`; + } + + const build = handleProfileUrls[social.platform]; + const handle = cleanHandle(social.platform, social.value); + if (!build || !handle) return null; + return build(encodeURIComponent(handle)); +} + +/** Mirrors the backend's SocialValidator. */ +export function isValidSocialValue(platform: SocialPlatform, value: string): boolean { + if (!value || value.length > SOCIAL_VALUE_MAX_LENGTH) return false; + if (/[\s\p{Cc}]/u.test(value)) return false; + + if (platform === SocialPlatform.Website) { + try { + const url = new URL(value); + return url.protocol === 'https:' || url.protocol === 'http:'; + } catch { + return false; + } + } + + return !value.includes('://') && !value.includes('/') && !value.includes('\\'); +} diff --git a/src/routes/(app)/profile/+page.svelte b/src/routes/(app)/profile/+page.svelte index e356b2cf..9692a81e 100644 --- a/src/routes/(app)/profile/+page.svelte +++ b/src/routes/(app)/profile/+page.svelte @@ -1,17 +1,335 @@ - - + + {#if self && saved?.isPublic} + + {/if} + + + {#if loading || !self} + + {:else} +
+
+ + + {m.profile_public_title()} + {m.profile_public_desc()} + + + + {#if form.isPublic} + + {/if} + + + + + + {m.profile_about_title()} + {m.profile_about_desc()} + + + + +
+ +