Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Fix Dag.Put
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Jan 9, 2019
1 parent 60321ed commit 5b2c99a
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,25 @@ package httpapi
import (
"context"
"fmt"
"github.com/ipfs/go-cid"
"io"
"math"

"github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"

caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"

"github.com/ipfs/go-cid"
"github.com/ipfs/go-ipld-format"
mh "github.com/multiformats/go-multihash"
)

type DagAPI HttpApi

func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (iface.ResolvedPath, error) {
func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPutOption) (iface.ResolvedPath, error) {
options, err := caopts.DagPutOptions(opts...)
if err != nil {
return nil, err
}

mht, ok := mh.Codes[options.MhType]
if !ok {
return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
}

codec, ok := cid.CodecToStr[options.Codec]
if !ok {
return nil, fmt.Errorf("unknowm codec %d", options.MhType)
Expand All @@ -39,12 +34,19 @@ func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...options.DagPu
var out struct{
Cid cid.Cid
}
err = api.core().request("dht/put").
Option("hash", mht).
req := api.core().request("dag/put").
Option("format", codec).
Option("input-enc", options.InputEnc).
FileBody(src).
Exec(ctx, &out)
Option("input-enc", options.InputEnc)

if options.MhType != math.MaxUint64 {
mht, ok := mh.Codes[options.MhType]
if !ok {
return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
}
req.Option("hash", mht)
}

err = req.FileBody(src).Exec(ctx, &out)
if err != nil {
return nil, err
}
Expand All @@ -56,7 +58,7 @@ func (api *DagAPI) Get(ctx context.Context, path iface.Path) (format.Node, error
panic("implement me")
}

func (api *DagAPI) Tree(ctx context.Context, path iface.Path, opts ...options.DagTreeOption) ([]iface.Path, error) {
func (api *DagAPI) Tree(ctx context.Context, path iface.Path, opts ...caopts.DagTreeOption) ([]iface.Path, error) {
panic("implement me")
}

Expand Down

0 comments on commit 5b2c99a

Please sign in to comment.