audio streaming app plyr.fm
38
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #1173 from zzstoatzz/feat/did-profile-urls

feat: support DID-based profile URLs for permalinks

authored by

nate nowack and committed by
GitHub
16316769 4a04843a

+38 -5
+8
frontend/src/routes/u/[handle]/+error.svelte
··· 6 6 7 7 const status = $page.status; 8 8 const handle = $page.params.handle; 9 + const isDid = handle?.startsWith('did:') ?? false; 9 10 10 11 let checkingBluesky = $state(false); 11 12 let blueskyProfileExists = $state(false); 12 13 let blueskyUrl = $state(''); 13 14 14 15 onMount(async () => { 16 + // bluesky handle resolution only works with handles, not DIDs 17 + if (isDid) return; 18 + 15 19 // if this is a 404, check if the handle exists on the ATProto network 16 20 if (status === 404 && handle) { 17 21 checkingBluesky = true; ··· 60 64 </a> 61 65 <a href="/" class="home-link">go home</a> 62 66 </div> 67 + {:else if isDid} 68 + <p class="error-message">we couldn't find anyone with this identifier</p> 69 + <p class="error-detail">{handle}</p> 70 + <a href="/" class="home-link">go home</a> 63 71 {:else} 64 72 <p class="error-message">we couldn't find anyone by @{handle}</p> 65 73 <p class="error-detail">the handle might not exist or could be misspelled</p>
+7 -2
frontend/src/routes/u/[handle]/+page.server.ts
··· 6 6 export const load: PageServerLoad = async ({ params, fetch }) => { 7 7 try { 8 8 // fetch artist info server-side for SEO/link previews 9 - const artistResponse = await fetch(`${API_URL}/artists/by-handle/${params.handle}`); 9 + // support both handle and DID in the URL for permalinks 10 + const isDid = params.handle.startsWith('did:'); 11 + const artistUrl = isDid 12 + ? `${API_URL}/artists/${params.handle}` 13 + : `${API_URL}/artists/by-handle/${params.handle}`; 14 + const artistResponse = await fetch(artistUrl); 10 15 11 16 if (!artistResponse.ok) { 12 17 throw error(404, 'artist not found'); ··· 27 32 nextCursor = data.next_cursor || null; 28 33 } 29 34 30 - const albumsResponse = await fetch(`${API_URL}/albums/${params.handle}`); 35 + const albumsResponse = await fetch(`${API_URL}/albums/${artist.handle}`); 31 36 let albums: ArtistAlbumSummary[] = []; 32 37 33 38 if (albumsResponse.ok) {
+11 -1
frontend/src/routes/u/[handle]/album/[slug]/+page.ts
··· 3 3 import { API_URL } from '$lib/config'; 4 4 5 5 export const load: PageLoad = async ({ params, fetch }) => { 6 - const response = await fetch(`${API_URL}/albums/${params.handle}/${params.slug}`, { 6 + // resolve DID to handle if needed (albums endpoint expects handle) 7 + let handle = params.handle; 8 + if (handle.startsWith('did:')) { 9 + const res = await fetch(`${API_URL}/artists/${handle}`); 10 + if (res.ok) { 11 + const artist = await res.json(); 12 + handle = artist.handle; 13 + } 14 + } 15 + 16 + const response = await fetch(`${API_URL}/albums/${handle}/${params.slug}`, { 7 17 credentials: 'include' 8 18 }); 9 19
+12 -2
frontend/src/routes/u/[handle]/liked/+page.ts
··· 1 1 import { browser } from '$app/environment'; 2 2 import { error } from '@sveltejs/kit'; 3 3 import { fetchUserLikes, type UserLikesResponse } from '$lib/tracks.svelte'; 4 + import { API_URL } from '$lib/config'; 4 5 import type { PageLoad } from './$types'; 5 6 6 7 export interface PageData { ··· 9 10 10 11 export const ssr = false; 11 12 12 - export const load: PageLoad = async ({ params }) => { 13 + export const load: PageLoad = async ({ params, fetch }) => { 13 14 if (!browser) { 14 15 return { userLikes: null }; 15 16 } 16 17 17 - const userLikes = await fetchUserLikes(params.handle); 18 + // resolve DID to handle if needed (likes endpoint expects handle) 19 + let handle = params.handle; 20 + if (handle.startsWith('did:')) { 21 + const res = await fetch(`${API_URL}/artists/${handle}`); 22 + if (!res.ok) throw error(404, 'user not found'); 23 + const artist = await res.json(); 24 + handle = artist.handle; 25 + } 26 + 27 + const userLikes = await fetchUserLikes(handle); 18 28 19 29 if (!userLikes) { 20 30 throw error(404, 'user not found');