From f8a7b003c1c838741e36d148a2caf537ccff7d0c Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Thu, 25 Sep 2025 16:18:22 -0700 Subject: [PATCH] Convert blossom store to conventions --- zooid/blossom.go | 37 +++++++++++++++++++++++-------------- zooid/instance.go | 13 ++++++++++++- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/zooid/blossom.go b/zooid/blossom.go index 2546210..b80145e 100644 --- a/zooid/blossom.go +++ b/zooid/blossom.go @@ -4,33 +4,45 @@ import ( "bytes" "context" "io" - "log" + "os" "net/url" "fiatjaf.com/nostr" + "fiatjaf.com/nostr/eventstore" "fiatjaf.com/nostr/khatru/blossom" - "github.com/gosimple/slug" "github.com/spf13/afero" ) -func EnableBlossom(instance *Instance) { - fs := afero.NewOsFs() +type BlossomStore struct { + Config *Config + Schema *Schema + Store eventstore.Store +} + +func (bl *BlossomStore) Init() error { dir := Env("DATA") + "/media" - if err := fs.MkdirAll(dir, 0755); err != nil { - log.Fatal("🚫 error creating blossom path:", err) + if err := os.MkdirAll(dir, 0755); err != nil { + return err } - store := &EventStore{ - Schema: &Schema{ - Name: slug.Make(instance.Config.Self.Schema) + "__blossom", - }, + // Blossom uses a wrapped event store for metadata + bl.Store = &EventStore{Schema: bl.Schema} + + if err := bl.Store.Init(); err != nil { + return err } + return nil +} + +func (bl *BlossomStore) Enable(instance *Instance) { + fs := afero.NewOsFs() + dir := Env("DATA") + "/media" backend := blossom.New(instance.Relay, "https://"+instance.Host) backend.Store = blossom.EventStoreBlobIndexWrapper{ - Store: store, + Store: bl.Store, ServiceURL: "https://" + instance.Host, } @@ -94,7 +106,4 @@ func EnableBlossom(instance *Instance) { return false, "", 200 } - if err := store.Init(); err != nil { - panic(err) - } } diff --git a/zooid/instance.go b/zooid/instance.go index 13587b3..ad1b97c 100644 --- a/zooid/instance.go +++ b/zooid/instance.go @@ -19,6 +19,7 @@ type Instance struct { Secret nostr.SecretKey Events eventstore.Store Access *AccessStore + Blossom *BlossomStore Management *ManagementStore Relay *khatru.Relay } @@ -55,6 +56,12 @@ func MakeInstance(hostname string) (*Instance, error) { Name: slug.Make(config.Self.Schema) + "__access", }, }, + Blossom: &BlossomStore{ + Config: config, + Schema: &Schema{ + Name: slug.Make(config.Self.Schema) + "__blossom", + }, + }, Management: &ManagementStore{ Config: config, Schema: &Schema{ @@ -96,6 +103,10 @@ func MakeInstance(hostname string) (*Instance, error) { log.Fatal("Failed to initialize access store:", err) } + if err := instance.Blossom.Init(); err != nil { + log.Fatal("Failed to initialize blossom store:", err) + } + if err := instance.Management.Init(); err != nil { log.Fatal("Failed to initialize management store:", err) } @@ -105,7 +116,7 @@ func MakeInstance(hostname string) (*Instance, error) { } if config.Blossom.Enabled { - EnableBlossom(instance) + instance.Blossom.Enable(instance) } if config.Management.Enabled {