mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-05 08:18:03 +08:00
coreapi unixfs: use session for resolving too
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
faf5230e69
commit
a4cb06027a
@ -18,17 +18,19 @@ import (
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
|
||||
logging "gx/ipfs/QmZChCsSt8DctjceaL56Eibc29CVQq4dGKRXC5JRZ6Ppae/go-log"
|
||||
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
||||
)
|
||||
|
||||
var log = logging.Logger("core/coreapi")
|
||||
|
||||
type CoreAPI struct {
|
||||
node *core.IpfsNode
|
||||
dag ipld.DAGService
|
||||
}
|
||||
|
||||
// NewCoreAPI creates new instance of IPFS CoreAPI backed by go-ipfs Node.
|
||||
func NewCoreAPI(n *core.IpfsNode) coreiface.CoreAPI {
|
||||
api := &CoreAPI{n}
|
||||
api := &CoreAPI{n, n.DAG}
|
||||
return api
|
||||
}
|
||||
|
||||
|
||||
@ -7,12 +7,13 @@ import (
|
||||
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
uio "gx/ipfs/QmWE6Ftsk98cG2MTVgH4wJT8VP2nL9TuBkYTrz9GSqcsh5/go-unixfs/io"
|
||||
ipfspath "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
|
||||
"gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path/resolver"
|
||||
|
||||
"gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
||||
dag "gx/ipfs/QmVvNkTCx8V9Zei8xuTYTBdUXmbnDRS4iNuw1SztYyhQwQ/go-merkledag"
|
||||
uio "gx/ipfs/QmWE6Ftsk98cG2MTVgH4wJT8VP2nL9TuBkYTrz9GSqcsh5/go-unixfs/io"
|
||||
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
||||
ipfspath "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
|
||||
"gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path/resolver"
|
||||
)
|
||||
|
||||
// ResolveNode resolves the path `p` using Unixfs resolver, gets and returns the
|
||||
@ -73,3 +74,8 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p coreiface.Path) (coreifac
|
||||
|
||||
return coreiface.NewResolvedPath(ipath, node, root, gopath.Join(rest...)), nil
|
||||
}
|
||||
|
||||
func (api *CoreAPI) getSession(ctx context.Context) *CoreAPI {
|
||||
ng := dag.NewReadOnlyDagService(dag.NewSession(ctx, api.dag))
|
||||
return &CoreAPI{api.node, ng}
|
||||
}
|
||||
|
||||
@ -134,13 +134,14 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.File, opts ...options
|
||||
}
|
||||
|
||||
func (api *UnixfsAPI) Get(ctx context.Context, p coreiface.Path) (coreiface.UnixfsFile, error) {
|
||||
nd, err := api.core().ResolveNode(ctx, p)
|
||||
ses := api.core().getSession(ctx)
|
||||
|
||||
nd, err := ses.ResolveNode(ctx, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ses := dag.NewReadOnlyDagService(dag.NewSession(ctx, api.node.DAG))
|
||||
return newUnixfsFile(ctx, ses, nd, "", nil)
|
||||
return newUnixfsFile(ctx, ses.dag, nd, "", nil)
|
||||
}
|
||||
|
||||
// Ls returns the contents of an IPFS or IPNS object(s) at path p, with the format:
|
||||
@ -173,6 +174,6 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path) ([]*ipld.Link, e
|
||||
return links, nil
|
||||
}
|
||||
|
||||
func (api *UnixfsAPI) core() coreiface.CoreAPI {
|
||||
func (api *UnixfsAPI) core() *CoreAPI {
|
||||
return (*CoreAPI)(api)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user