From 078ee94465e984aeacf71e89210e6d2f42bef385 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 22 Apr 2026 15:16:40 -0300 Subject: [PATCH] sdk: FetchBlossomServerList(). --- sdk/lists_other.go | 34 ++++++++++++++++++++++++++++++++++ sdk/system.go | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 sdk/lists_other.go diff --git a/sdk/lists_other.go b/sdk/lists_other.go new file mode 100644 index 0000000..1e41074 --- /dev/null +++ b/sdk/lists_other.go @@ -0,0 +1,34 @@ +package sdk + +import ( + "context" + + "fiatjaf.com/nostr" + cache_memory "fiatjaf.com/nostr/sdk/cache/memory" +) + +type BlossomURL string + +func (r BlossomURL) Value() string { return string(r) } + +func (sys *System) FetchBlossomServerList(ctx context.Context, pubkey nostr.PubKey) GenericList[string, BlossomURL] { + sys.blossomServerListCacheOnce.Do(func() { + if sys.BlossomServerListCache == nil { + sys.BlossomServerListCache = cache_memory.New[GenericList[string, BlossomURL]](1000) + } + }) + + ml, _ := fetchGenericList(sys, ctx, pubkey, 10101, kind_10101, func(t nostr.Tag) (BlossomURL, bool) { + if len(t) < 2 { + return "", false + } + + nm, err := nostr.NormalizeHTTPURL(t[1]) + if err != nil { + return "", false + } + + return BlossomURL(nm), true + }, sys.BlossomServerListCache) + return ml +} diff --git a/sdk/system.go b/sdk/system.go index 2677427..4aa19bf 100644 --- a/sdk/system.go +++ b/sdk/system.go @@ -61,6 +61,8 @@ type System struct { MediaFollowListCache cache.Cache32[GenericList[nostr.PubKey, ProfileRef]] goodWikiAuthorListCacheOnce sync.Once GoodWikiAuthorListCache cache.Cache32[GenericList[nostr.PubKey, ProfileRef]] + blossomServerListCacheOnce sync.Once + BlossomServerListCache cache.Cache32[GenericList[string, BlossomURL]] gitAuthorListCacheOnce sync.Once GitAuthorListCache cache.Cache32[GenericList[nostr.PubKey, ProfileRef]] relaySetsCacheOnce sync.Once