forked from coracle/zooid
Add sqlite backend
This commit is contained in:
+15
-13
@@ -8,9 +8,9 @@ import (
|
||||
"net/url"
|
||||
|
||||
"fiatjaf.com/nostr"
|
||||
"fiatjaf.com/nostr/eventstore/lmdb"
|
||||
"fiatjaf.com/nostr/khatru/blossom"
|
||||
"github.com/spf13/afero"
|
||||
"zooid/sqlite"
|
||||
)
|
||||
|
||||
func EnableBlossom(instance *Instance) {
|
||||
@@ -20,16 +20,15 @@ func EnableBlossom(instance *Instance) {
|
||||
log.Fatal("🚫 error creating blossom path:", err)
|
||||
}
|
||||
|
||||
backend := &lmdb.LMDBBackend{Path: instance.Config.Data.Blossom}
|
||||
if err := backend.Init(); err != nil {
|
||||
panic(err)
|
||||
store := &sqlite.SqliteBackend{
|
||||
Path: instance.Config.Data.Blossom,
|
||||
}
|
||||
|
||||
blossom := blossom.New(instance.Relay, "https://"+instance.Host)
|
||||
backend := blossom.New(instance.Relay, "https://"+instance.Host)
|
||||
|
||||
blossom.Store = backend
|
||||
backend.Store = blossom.EventStoreBlobIndexWrapper{Store: store, ServiceURL: "https://" + instance.Host}
|
||||
|
||||
blossom.StoreBlob = func(ctx context.Context, sha256 string, ext string, body []byte) error {
|
||||
backend.StoreBlob = func(ctx context.Context, sha256 string, ext string, body []byte) error {
|
||||
file, err := fs.Create(instance.Config.Blossom.Directory + "/" + sha256)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -42,7 +41,7 @@ func EnableBlossom(instance *Instance) {
|
||||
return nil
|
||||
}
|
||||
|
||||
blossom.LoadBlob = func(ctx context.Context, sha256 string, ext string) (io.ReadSeeker, *url.URL, error) {
|
||||
backend.LoadBlob = func(ctx context.Context, sha256 string, ext string) (io.ReadSeeker, *url.URL, error) {
|
||||
file, err := fs.Open(instance.Config.Blossom.Directory + "/" + sha256)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -50,11 +49,11 @@ func EnableBlossom(instance *Instance) {
|
||||
return file, nil, nil
|
||||
}
|
||||
|
||||
blossom.DeleteBlob = func(ctx context.Context, sha256 string, ext string) error {
|
||||
backend.DeleteBlob = func(ctx context.Context, sha256 string, ext string) error {
|
||||
return fs.Remove(instance.Config.Blossom.Directory + "/" + sha256)
|
||||
}
|
||||
|
||||
blossom.RejectUpload = func(ctx context.Context, auth *nostr.Event, size int, ext string) (bool, string, int) {
|
||||
backend.RejectUpload = func(ctx context.Context, auth *nostr.Event, size int, ext string) (bool, string, int) {
|
||||
if size > 10*1024*1024 {
|
||||
return true, "file too large", 413
|
||||
}
|
||||
@@ -66,7 +65,7 @@ func EnableBlossom(instance *Instance) {
|
||||
return false, ext, size
|
||||
}
|
||||
|
||||
blossom.RejectGet = func(ctx context.Context, auth *nostr.Event, sha256 string, ext string) (bool, string, int) {
|
||||
backend.RejectGet = func(ctx context.Context, auth *nostr.Event, sha256 string, ext string) (bool, string, int) {
|
||||
if auth == nil || !instance.IsMember(auth.PubKey) {
|
||||
return true, "unauthorized", 403
|
||||
}
|
||||
@@ -74,7 +73,7 @@ func EnableBlossom(instance *Instance) {
|
||||
return false, "", 200
|
||||
}
|
||||
|
||||
blossom.RejectList = func(ctx context.Context, auth *nostr.Event, pubkey nostr.PubKey) (bool, string, int) {
|
||||
backend.RejectList = func(ctx context.Context, auth *nostr.Event, pubkey nostr.PubKey) (bool, string, int) {
|
||||
if auth == nil || !instance.IsMember(auth.PubKey) {
|
||||
return true, "unauthorized", 403
|
||||
}
|
||||
@@ -82,11 +81,14 @@ func EnableBlossom(instance *Instance) {
|
||||
return false, "", 200
|
||||
}
|
||||
|
||||
blossom.RejectDelete = func(ctx context.Context, auth *nostr.Event, sha256 string, ext string) (bool, string, int) {
|
||||
backend.RejectDelete = func(ctx context.Context, auth *nostr.Event, sha256 string, ext string) (bool, string, int) {
|
||||
if auth == nil || !instance.IsMember(auth.PubKey) {
|
||||
return true, "unauthorized", 403
|
||||
}
|
||||
|
||||
return false, "", 200
|
||||
}
|
||||
if err := store.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user