mirror of
https://github.com/aljazceru/haven.git
synced 2025-12-18 22:24:22 +01:00
add blossom after routes
This commit is contained in:
28
init.go
28
init.go
@@ -1,16 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fiatjaf/eventstore/badger"
|
"github.com/fiatjaf/eventstore/badger"
|
||||||
"github.com/fiatjaf/eventstore/lmdb"
|
"github.com/fiatjaf/eventstore/lmdb"
|
||||||
"github.com/fiatjaf/khatru"
|
"github.com/fiatjaf/khatru"
|
||||||
"github.com/fiatjaf/khatru/blossom"
|
|
||||||
"github.com/fiatjaf/khatru/policies"
|
"github.com/fiatjaf/khatru/policies"
|
||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
)
|
)
|
||||||
@@ -229,30 +225,6 @@ func initRelays() {
|
|||||||
outboxRelayLimits.ConnectionRateLimiterMaxTokens,
|
outboxRelayLimits.ConnectionRateLimiterMaxTokens,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
addr := fmt.Sprintf("%s:%d", config.RelayBindAddress, config.BlossomPort)
|
|
||||||
|
|
||||||
bl := blossom.New(outboxRelay, addr)
|
|
||||||
bl.Store = blossom.EventStoreBlobIndexWrapper{Store: outboxDB, ServiceURL: bl.ServiceURL}
|
|
||||||
bl.StoreBlob = append(bl.StoreBlob, func(ctx context.Context, sha256 string, body []byte) error {
|
|
||||||
if khatru.GetAuthed(ctx) != nPubToPubkey(config.OwnerNpub) {
|
|
||||||
return fmt.Errorf("auth-required: only the relay owner can store media")
|
|
||||||
}
|
|
||||||
|
|
||||||
file, err := fs.Create(config.BlossomPath + sha256)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := io.Copy(file, bytes.NewReader(body)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
bl.LoadBlob = append(bl.LoadBlob, func(ctx context.Context, sha256 string) (io.Reader, error) {
|
|
||||||
return fs.Open(config.BlossomPath + sha256)
|
|
||||||
})
|
|
||||||
bl.DeleteBlob = append(bl.DeleteBlob, func(ctx context.Context, sha256 string) error {
|
|
||||||
return fs.Remove(config.BlossomPath + sha256)
|
|
||||||
})
|
|
||||||
|
|
||||||
inboxRelay.Info.Name = config.InboxRelayName
|
inboxRelay.Info.Name = config.InboxRelayName
|
||||||
inboxRelay.Info.PubKey = nPubToPubkey(config.InboxRelayNpub)
|
inboxRelay.Info.PubKey = nPubToPubkey(config.InboxRelayNpub)
|
||||||
|
|||||||
28
main.go
28
main.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/fiatjaf/khatru"
|
"github.com/fiatjaf/khatru"
|
||||||
|
"github.com/fiatjaf/khatru/blossom"
|
||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
"github.com/puzpuzpuz/xsync/v3"
|
"github.com/puzpuzpuz/xsync/v3"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
@@ -285,6 +287,32 @@ func makeNewRelay(relayType string, w http.ResponseWriter, r *http.Request) *kha
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
addr := fmt.Sprintf("%s:%d", config.RelayBindAddress, config.RelayPort)
|
||||||
|
|
||||||
|
bl := blossom.New(outboxRelay, addr)
|
||||||
|
bl.Store = blossom.EventStoreBlobIndexWrapper{Store: outboxDB, ServiceURL: bl.ServiceURL}
|
||||||
|
bl.StoreBlob = append(bl.StoreBlob, func(ctx context.Context, sha256 string, body []byte) error {
|
||||||
|
if khatru.GetAuthed(ctx) != nPubToPubkey(config.OwnerNpub) {
|
||||||
|
return fmt.Errorf("auth-required: only the relay owner can store media")
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := fs.Create(config.BlossomPath + sha256)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := io.Copy(file, bytes.NewReader(body)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
bl.LoadBlob = append(bl.LoadBlob, func(ctx context.Context, sha256 string) (io.Reader, error) {
|
||||||
|
return fs.Open(config.BlossomPath + sha256)
|
||||||
|
})
|
||||||
|
bl.DeleteBlob = append(bl.DeleteBlob, func(ctx context.Context, sha256 string) error {
|
||||||
|
return fs.Remove(config.BlossomPath + sha256)
|
||||||
|
})
|
||||||
|
|
||||||
return outboxRelay
|
return outboxRelay
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user