Live video on the AT Protocol
at natb/block-javascript-protocol 42 lines 917 B view raw
1package discord 2 3import ( 4 "context" 5 "sync" 6 7 "github.com/bluesky-social/indigo/api/bsky" 8 "github.com/bluesky-social/indigo/xrpc" 9 "stream.place/streamplace/pkg/aqhttp" 10) 11 12var avatarCache = make(map[string]string) 13var avatarCacheMutex = sync.Mutex{} 14 15// getAvatarURL gets the avatar URL for a Bluesky from the public appview 16// pretty ugly. we're going to replace this with indexing bluesky profiles 17// at some point. 18func GetAvatarURL(ctx context.Context, did string) (string, error) { 19 avatarCacheMutex.Lock() 20 defer avatarCacheMutex.Unlock() 21 22 if avatar, ok := avatarCache[did]; ok { 23 return avatar, nil 24 } 25 26 xrpc := &xrpc.Client{ 27 Host: "https://public.api.bsky.app", 28 Client: &aqhttp.Client, 29 } 30 31 profile, err := bsky.ActorGetProfile(ctx, xrpc, did) 32 if err != nil { 33 return "", err 34 } 35 36 if profile.Avatar != nil { 37 avatarCache[did] = *profile.Avatar 38 return *profile.Avatar, nil 39 } 40 41 return "", nil 42}