Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
915 B · 42 lines
12345678910111213141516171819202122232425262728293031323334353637383940414243package discord
import ( "context" "sync"
"github.com/bluesky-social/indigo/xrpc" "stream.place/streamplace/pkg/appbsky" "stream.place/streamplace/pkg/aqhttp")
var avatarCache = make(map[string]string)var avatarCacheMutex = sync.Mutex{}
// getAvatarURL gets the avatar URL for a Bluesky from the public appview// pretty ugly. we're going to replace this with indexing bluesky profiles// at some point.func GetAvatarURL(ctx context.Context, did string) (string, error) { avatarCacheMutex.Lock() defer avatarCacheMutex.Unlock()
if avatar, ok := avatarCache[did]; ok { return avatar, nil }
xrpc := &xrpc.Client{ Host: "https://public.api.bsky.app", Client: &aqhttp.Client, }
profile, err := appbsky.ActorGetProfile(ctx, xrpc, did) if err != nil { return "", err }
if profile.Avatar != nil { avatarCache[did] = *profile.Avatar return *profile.Avatar, nil }
return "", nil}