file to client
This commit is contained in:
29 files changed
+385
-387
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonfile/fileserver"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/metric"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/account"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/api"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/filepogreb"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace/nodecache"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/storage"
|
||||
@@ -102,6 +104,8 @@ func Bootstrap(a *app.App) {
|
||||
Register(pool.New()).
|
||||
Register(nodespace.New()).
|
||||
Register(commonspace.New()).
|
||||
Register(filepogreb.New()).
|
||||
Register(fileserver.New()).
|
||||
Register(server.New()).
|
||||
Register(api.New())
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package filepogreb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/akrylysov/pogreb"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonfile/fileblockstore"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
|
||||
blocks "github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
)
|
||||
|
||||
const CName = fileblockstore.CName
|
||||
|
||||
func New() Store {
|
||||
return &store{}
|
||||
}
|
||||
|
||||
type Store interface {
|
||||
app.ComponentRunnable
|
||||
fileblockstore.BlockStore
|
||||
}
|
||||
|
||||
type configSource interface {
|
||||
GetFileStorePogreb() config.FileStorePogreb
|
||||
}
|
||||
|
||||
type store struct {
|
||||
db *pogreb.DB
|
||||
conf config.FileStorePogreb
|
||||
}
|
||||
|
||||
func (s *store) Init(a *app.App) (err error) {
|
||||
s.conf = a.MustComponent("config").(configSource).GetFileStorePogreb()
|
||||
return
|
||||
}
|
||||
|
||||
func (s *store) Name() (name string) {
|
||||
return CName
|
||||
}
|
||||
|
||||
func (s *store) Run(ctx context.Context) (err error) {
|
||||
if s.db, err = pogreb.Open(s.conf.Path, &pogreb.Options{}); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *store) Get(ctx context.Context, k cid.Cid) (blocks.Block, error) {
|
||||
val, err := s.db.Get(k.Bytes())
|
||||
if err != nil {
|
||||
return nil, fileblockstore.ErrCIDNotFound
|
||||
}
|
||||
return blocks.NewBlock(val), nil
|
||||
}
|
||||
|
||||
func (s *store) GetMany(ctx context.Context, ks []cid.Cid) <-chan blocks.Block {
|
||||
var res = make(chan blocks.Block)
|
||||
go func() {
|
||||
defer close(res)
|
||||
for _, k := range ks {
|
||||
b, err := s.Get(ctx, k)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case res <- b:
|
||||
}
|
||||
}
|
||||
}()
|
||||
return res
|
||||
}
|
||||
|
||||
func (s *store) Add(ctx context.Context, bs []blocks.Block) error {
|
||||
for _, b := range bs {
|
||||
if err := s.db.Put(b.Cid().Bytes(), b.RawData()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *store) Delete(ctx context.Context, c cid.Cid) error {
|
||||
return s.db.Delete(c.Bytes())
|
||||
}
|
||||
|
||||
func (s *store) Close(ctx context.Context) (err error) {
|
||||
if s.db != nil {
|
||||
return s.db.Close()
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in new issue
Block a user