Monorepo for Tangled tangled.org

avatar: fetch tangled avatar before falling back to bsky & random color #893

merged opened by anirudh.fi targeting master from icy/tolqpt
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:hwevmowznbiukdf6uk5dwrrq/sh.tangled.repo.pull/3m7znwnzpyn22
+31 -6
Diff #1
+31 -6
avatar/src/index.js
··· 23 23 } 24 24 25 25 const size = searchParams.get("size"); 26 + const blobUrl = searchParams.get("blob"); // URL to fetch Tangled avatar from PDS 26 27 const resizeToTiny = size === "tiny"; 27 28 28 29 const cache = caches.default; ··· 56 57 message: "avatar request for: " + actor, 57 58 computedSignature: computedSig, 58 59 providedSignature: signatureHex, 60 + hasBlobUrl: !!blobUrl, 59 61 }); 60 62 61 63 const sigBytes = Uint8Array.from( ··· 68 70 } 69 71 70 72 try { 71 - const profileResponse = await fetch( 72 - `https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${actor}`, 73 - ); 74 - const profile = await profileResponse.json(); 75 - const avatar = profile.avatar; 73 + let avatarUrl = null; 74 + 75 + // If blob URL is provided, use it (Tangled profile avatar from user's PDS) 76 + if (blobUrl) { 77 + try { 78 + const decodedBlobUrl = decodeURIComponent(blobUrl); 79 + console.log({ 80 + level: "debug", 81 + message: "fetching Tangled avatar from PDS", 82 + actor: actor, 83 + blobUrl: decodedBlobUrl, 84 + }); 85 + avatarUrl = decodedBlobUrl; 86 + } catch (e) { 87 + console.log({ 88 + level: "warn", 89 + message: "failed to decode blob URL, falling back to Bluesky", 90 + error: e.message, 91 + }); 92 + } 93 + } 76 94 77 - let avatarUrl = profile.avatar; 95 + // If no blob URL or it failed, fall back to Bluesky 96 + if (!avatarUrl) { 97 + const profileResponse = await fetch( 98 + `https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${actor}`, 99 + ); 100 + const profile = await profileResponse.json(); 101 + avatarUrl = profile.avatar; 102 + } 78 103 79 104 if (!avatarUrl) { 80 105 // Generate a random color based on the actor string

History

7 rounds 2 comments
sign up or login to add to the discussion
1 commit
expand
avatar: fetch tangled avatar before falling back to bsky & random color
3/3 success
expand
expand 0 comments
pull request successfully merged
1 commit
expand
avatar: fetch tangled avatar before falling back to bsky & random color
3/3 success
expand
expand 0 comments
1 commit
expand
avatar: fetch tangled avatar before falling back to bsky & random color
3/3 success
expand
expand 0 comments
1 commit
expand
avatar: fetch tangled avatar before falling back to bsky & random color
3/3 success
expand
expand 0 comments
1 commit
expand
avatar: fetch tangled avatar before falling back to bsky & random color
expand 0 comments
1 commit
expand
avatar: fetch tangled avatar before falling back to bsky & random color
expand 2 comments

why do we do this (just out of curiosity): !!blob:

  • we can cast using Boolean(blobUrl)
  • or be more explicit: blobUrl != null && blobUrl != ""

Didn't know about Boolean(blobUrl)! (also this was Claude)

1 commit
expand
avatar: fetch tangled avatar before falling back to bsky & random color
expand 0 comments