Convert blossom store to conventions
This commit is contained in:
+23
-14
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user