fix syu.is avatar cid
This commit is contained in:
@@ -102,13 +102,51 @@ export async function getProfile(actor: string): Promise<Profile> {
|
||||
try {
|
||||
const agent = getAgent(endpoint)
|
||||
const res = await agent.getProfile({ actor })
|
||||
|
||||
let avatar = res.data.avatar
|
||||
let banner = res.data.banner
|
||||
|
||||
// If avatar uses cdn.bsky.app but user's PDS is not bsky, fetch from their PDS
|
||||
const did = res.data.did
|
||||
if (avatar && avatar.includes('cdn.bsky.app')) {
|
||||
try {
|
||||
const pds = await resolvePds(did)
|
||||
// If PDS is not bsky.social/bsky.network, reconstruct avatar URL from blob
|
||||
if (pds && !pds.includes('bsky.social') && !pds.includes('bsky.network')) {
|
||||
const pdsAgent = getAgent(pds)
|
||||
const profileRecord = await pdsAgent.com.atproto.repo.getRecord({
|
||||
repo: did,
|
||||
collection: 'app.bsky.actor.profile',
|
||||
rkey: 'self',
|
||||
})
|
||||
const avatarBlob = (profileRecord.data.value as any)?.avatar
|
||||
if (avatarBlob?.ref) {
|
||||
// ref can be either { $link: "..." } or a CID object with toString()
|
||||
const cid = avatarBlob.ref.$link || avatarBlob.ref.toString?.()
|
||||
if (cid) {
|
||||
avatar = `${pds}/xrpc/com.atproto.sync.getBlob?did=${did}&cid=${cid}`
|
||||
}
|
||||
}
|
||||
const bannerBlob = (profileRecord.data.value as any)?.banner
|
||||
if (bannerBlob?.ref) {
|
||||
const cid = bannerBlob.ref.$link || bannerBlob.ref.toString?.()
|
||||
if (cid) {
|
||||
banner = `${pds}/xrpc/com.atproto.sync.getBlob?did=${did}&cid=${cid}`
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Keep original avatar if blob fetch fails
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
did: res.data.did,
|
||||
handle: res.data.handle,
|
||||
displayName: res.data.displayName,
|
||||
description: res.data.description,
|
||||
avatar: res.data.avatar,
|
||||
banner: res.data.banner,
|
||||
avatar,
|
||||
banner,
|
||||
}
|
||||
} catch {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user