From 19a2341ddc9e11b8e79d82c826b068b9cce74b97 Mon Sep 17 00:00:00 2001 From: syui Date: Sat, 17 Jan 2026 13:16:53 +0900 Subject: [PATCH] fix syu.is avatar cid --- src/lib/api.ts | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/lib/api.ts b/src/lib/api.ts index 0eefe4f..e92c328 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -102,13 +102,51 @@ export async function getProfile(actor: string): Promise { 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