Convert blossom store to conventions
This commit is contained in:
+23
-14
@@ -4,33 +4,45 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"os"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
|
"fiatjaf.com/nostr/eventstore"
|
||||||
"fiatjaf.com/nostr/khatru/blossom"
|
"fiatjaf.com/nostr/khatru/blossom"
|
||||||
"github.com/gosimple/slug"
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
func EnableBlossom(instance *Instance) {
|
type BlossomStore struct {
|
||||||
fs := afero.NewOsFs()
|
Config *Config
|
||||||
|
Schema *Schema
|
||||||
|
Store eventstore.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bl *BlossomStore) Init() error {
|
||||||
dir := Env("DATA") + "/media"
|
dir := Env("DATA") + "/media"
|
||||||
|
|
||||||
if err := fs.MkdirAll(dir, 0755); err != nil {
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||||
log.Fatal("🚫 error creating blossom path:", err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
store := &EventStore{
|
// Blossom uses a wrapped event store for metadata
|
||||||
Schema: &Schema{
|
bl.Store = &EventStore{Schema: bl.Schema}
|
||||||
Name: slug.Make(instance.Config.Self.Schema) + "__blossom",
|
|
||||||
},
|
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 := blossom.New(instance.Relay, "https://"+instance.Host)
|
||||||
|
|
||||||
backend.Store = blossom.EventStoreBlobIndexWrapper{
|
backend.Store = blossom.EventStoreBlobIndexWrapper{
|
||||||
Store: store,
|
Store: bl.Store,
|
||||||
ServiceURL: "https://" + instance.Host,
|
ServiceURL: "https://" + instance.Host,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +106,4 @@ func EnableBlossom(instance *Instance) {
|
|||||||
|
|
||||||
return false, "", 200
|
return false, "", 200
|
||||||
}
|
}
|
||||||
if err := store.Init(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-1
@@ -19,6 +19,7 @@ type Instance struct {
|
|||||||
Secret nostr.SecretKey
|
Secret nostr.SecretKey
|
||||||
Events eventstore.Store
|
Events eventstore.Store
|
||||||
Access *AccessStore
|
Access *AccessStore
|
||||||
|
Blossom *BlossomStore
|
||||||
Management *ManagementStore
|
Management *ManagementStore
|
||||||
Relay *khatru.Relay
|
Relay *khatru.Relay
|
||||||
}
|
}
|
||||||
@@ -55,6 +56,12 @@ func MakeInstance(hostname string) (*Instance, error) {
|
|||||||
Name: slug.Make(config.Self.Schema) + "__access",
|
Name: slug.Make(config.Self.Schema) + "__access",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Blossom: &BlossomStore{
|
||||||
|
Config: config,
|
||||||
|
Schema: &Schema{
|
||||||
|
Name: slug.Make(config.Self.Schema) + "__blossom",
|
||||||
|
},
|
||||||
|
},
|
||||||
Management: &ManagementStore{
|
Management: &ManagementStore{
|
||||||
Config: config,
|
Config: config,
|
||||||
Schema: &Schema{
|
Schema: &Schema{
|
||||||
@@ -96,6 +103,10 @@ func MakeInstance(hostname string) (*Instance, error) {
|
|||||||
log.Fatal("Failed to initialize access store:", err)
|
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 {
|
if err := instance.Management.Init(); err != nil {
|
||||||
log.Fatal("Failed to initialize management store:", err)
|
log.Fatal("Failed to initialize management store:", err)
|
||||||
}
|
}
|
||||||
@@ -105,7 +116,7 @@ func MakeInstance(hostname string) (*Instance, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.Blossom.Enabled {
|
if config.Blossom.Enabled {
|
||||||
EnableBlossom(instance)
|
instance.Blossom.Enable(instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Management.Enabled {
|
if config.Management.Enabled {
|
||||||
|
|||||||
Reference in New Issue
Block a user