audio streaming app plyr.fm
38
fork

Configure Feed

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

replace manual AT-URI parsing with library utilities (#1208)

use parse_at_uri() (Python) and AtUri (TypeScript) instead of
hand-rolled .split("/") patterns across 5 backend and 2 frontend
call sites.

closes #1207

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

authored by

nate nowack
Claude Opus 4.6
and committed by
GitHub
5ce55496 6512dcef

+12 -13
+4 -6
backend/src/backend/api/lists.py
··· 20 20 21 21 from backend._internal import Session as AuthSession 22 22 from backend._internal import get_optional_session, require_auth 23 + from backend._internal.atproto.client import parse_at_uri 23 24 from backend._internal.atproto.records import ( 24 25 _reconstruct_oauth_session, 25 26 create_list_record, ··· 588 589 oauth_session = _reconstruct_oauth_session(oauth_data) 589 590 from backend._internal import get_oauth_client 590 591 591 - parts = playlist.atproto_record_uri.replace("at://", "").split("/") 592 - repo, collection, rkey = parts 592 + repo, collection, rkey = parse_at_uri(playlist.atproto_record_uri) 593 593 594 594 url = f"{oauth_data['pds_url']}/xrpc/com.atproto.repo.getRecord" 595 595 params = {"repo": repo, "collection": collection, "rkey": rkey} ··· 701 701 oauth_session = _reconstruct_oauth_session(oauth_data) 702 702 from backend._internal import get_oauth_client 703 703 704 - parts = playlist.atproto_record_uri.replace("at://", "").split("/") 705 - repo, collection, rkey = parts 704 + repo, collection, rkey = parse_at_uri(playlist.atproto_record_uri) 706 705 707 706 url = f"{oauth_data['pds_url']}/xrpc/com.atproto.repo.getRecord" 708 707 params = {"repo": repo, "collection": collection, "rkey": rkey} ··· 905 904 906 905 oauth_session = _reconstruct_oauth_session(oauth_data) 907 906 908 - parts = playlist.atproto_record_uri.replace("at://", "").split("/") 909 - repo, collection, rkey = parts 907 + repo, collection, rkey = parse_at_uri(playlist.atproto_record_uri) 910 908 911 909 url = f"{oauth_data['pds_url']}/xrpc/com.atproto.repo.getRecord" 912 910 params = {"repo": repo, "collection": collection, "rkey": rkey}
+2 -2
backend/src/backend/api/migration.py
··· 8 8 9 9 from backend._internal import Session as AuthSession 10 10 from backend._internal import require_auth 11 - from backend._internal.atproto.client import make_pds_request 11 + from backend._internal.atproto.client import make_pds_request, parse_at_uri 12 12 from backend.config import settings 13 13 14 14 logger = logging.getLogger(__name__) ··· 189 189 # delete old record after successful migration 190 190 old_uri = old_record.get("uri", "") 191 191 if old_uri: 192 - rkey = old_uri.split("/")[-1] 192 + _, _, rkey = parse_at_uri(old_uri) 193 193 try: 194 194 await make_pds_request( 195 195 session,
+2 -1
backend/src/backend/schemas.py
··· 4 4 5 5 from pydantic import BaseModel, Field 6 6 7 + from backend._internal.atproto.client import parse_at_uri 7 8 from backend.models import Album, Track 8 9 from backend.utilities.aggregations import CopyrightInfo 9 10 ··· 175 176 if track.atproto_record_uri and pds_url: 176 177 from backend.config import settings 177 178 178 - rkey = track.atproto_record_uri.split("/")[-1] 179 + _, _, rkey = parse_at_uri(track.atproto_record_uri) 179 180 atproto_record_url = ( 180 181 f"{pds_url}/xrpc/com.atproto.repo.getRecord" 181 182 f"?repo={track.artist_did}&collection={settings.atproto.track_collection}"
+2 -2
frontend/src/routes/playlist/[id]/+page.svelte
··· 1 1 <script lang="ts"> 2 + import { AtUri } from "@atproto/api"; 2 3 import Header from "$lib/components/Header.svelte"; 3 4 import ShareButton from "$lib/components/ShareButton.svelte"; 4 5 import SensitiveImage from "$lib/components/SensitiveImage.svelte"; ··· 453 454 async function saveOrder() { 454 455 if (!playlist.atproto_record_uri) return; 455 456 456 - // extract rkey from list URI (at://did/collection/rkey) 457 - const rkey = playlist.atproto_record_uri.split("/").pop(); 457 + const rkey = new AtUri(playlist.atproto_record_uri).rkey; 458 458 if (!rkey) return; 459 459 460 460 // build strongRefs from current track order
+2 -2
frontend/src/routes/u/[handle]/album/[slug]/+page.svelte
··· 1 1 <script lang="ts"> 2 + import { AtUri } from '@atproto/api'; 2 3 import { goto } from '$app/navigation'; 3 4 import Header from '$lib/components/Header.svelte'; 4 5 import TrackItem from '$lib/components/TrackItem.svelte'; ··· 254 255 async function saveOrder() { 255 256 if (!albumMetadata.list_uri) return; 256 257 257 - // extract rkey from list URI (at://did/collection/rkey) 258 - const rkey = albumMetadata.list_uri.split('/').pop(); 258 + const rkey = new AtUri(albumMetadata.list_uri).rkey; 259 259 if (!rkey) return; 260 260 261 261 // build strongRefs from current track order