fix social-app service link pds
This commit is contained in:
@@ -3,7 +3,6 @@ import {Pressable, View} from 'react-native'
|
||||
import {type AppBskyActorDefs} from '@atproto/api'
|
||||
import {useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {BSKY_SERVICE} from '#/lib/constants'
|
||||
import {useOpenLink} from '#/lib/hooks/useOpenLink'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import {Text} from '#/components/Typography'
|
||||
@@ -66,6 +65,26 @@ const SERVICE_CONFIG: Record<
|
||||
},
|
||||
}
|
||||
|
||||
// --- PDS Resolution ---
|
||||
|
||||
async function resolvePds(did: string): Promise<string> {
|
||||
if (did.startsWith('did:web:')) {
|
||||
const host = did.split(':').slice(2).join(':')
|
||||
const res = await fetch(`https://${host}/.well-known/did.json`)
|
||||
if (!res.ok) throw new Error('failed to resolve did:web')
|
||||
const doc = await res.json()
|
||||
const pds = doc.service?.find((s: any) => s.id === '#atproto_pds')?.serviceEndpoint
|
||||
if (pds) return pds
|
||||
return `https://${host}`
|
||||
}
|
||||
const res = await fetch(`https://plc.directory/${did}`)
|
||||
if (!res.ok) throw new Error('failed to resolve DID')
|
||||
const doc = await res.json()
|
||||
const pds = doc.service?.find((s: any) => s.id === '#atproto_pds')?.serviceEndpoint
|
||||
if (!pds) throw new Error('no PDS found')
|
||||
return pds
|
||||
}
|
||||
|
||||
// --- Component ---
|
||||
|
||||
export function ProfileAtLinks({
|
||||
@@ -79,8 +98,9 @@ export function ProfileAtLinks({
|
||||
const {data: linkData} = useQuery({
|
||||
queryKey: ['at-links', profile.did],
|
||||
queryFn: async () => {
|
||||
const pds = await resolvePds(profile.did)
|
||||
const res = await fetch(
|
||||
`${BSKY_SERVICE}/xrpc/com.atproto.repo.getRecord?repo=${encodeURIComponent(profile.did)}&collection=ai.syui.at.link&rkey=self`,
|
||||
`${pds}/xrpc/com.atproto.repo.getRecord?repo=${encodeURIComponent(profile.did)}&collection=ai.syui.at.link&rkey=self`,
|
||||
)
|
||||
if (!res.ok) throw new Error('not found')
|
||||
const json = await res.json()
|
||||
|
||||
Reference in New Issue
Block a user