@cryptotaxi247 / kubo / commits / 31a4c3754

Fix Dag.Put

This commit was moved from ipfs/go-ipfs-http-client@5b2c99abdedaf464f061511bc7b24b1ade66546f

Łukasz Magiera committed Jan 9, 2019 at 09:47 UTC 31a4c3754b87e68f60525533ba9c6bb9c0b1021e
1 file changed +17 -15
client/httpapi/dag.go
+17 -15
@@ -3,30 +3,25 @@ package httpapi
3 import (
4 "context"
5 "fmt"
6 - "github.com/ipfs/go-cid"
6 "io"
7 + "math"
8
9 "github.com/ipfs/go-ipfs/core/coreapi/interface"
10 - "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11 -
10 caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11 +
12 + "github.com/ipfs/go-cid"
13 "github.com/ipfs/go-ipld-format"
14 mh "github.com/multiformats/go-multihash"
15 )
16
17 type DagAPI HttpApi
18
19 -func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (iface.ResolvedPath, error) {
19 +func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPutOption) (iface.ResolvedPath, error) {
20 options, err := caopts.DagPutOptions(opts...)
21 if err != nil {
22 return nil, err
23 }
24
25 - mht, ok := mh.Codes[options.MhType]
26 - if !ok {
27 - return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
28 - }
29 -
25 codec, ok := cid.CodecToStr[options.Codec]
26 if !ok {
27 return nil, fmt.Errorf("unknowm codec %d", options.MhType)
@@ -39,12 +34,19 @@ func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...options.DagPu
34 var out struct{
35 Cid cid.Cid
36 }
42 - err = api.core().request("dht/put").
43 - Option("hash", mht).
37 + req := api.core().request("dag/put").
38 Option("format", codec).
45 - Option("input-enc", options.InputEnc).
46 - FileBody(src).
47 - Exec(ctx, &out)
39 + Option("input-enc", options.InputEnc)
40 +
41 + if options.MhType != math.MaxUint64 {
42 + mht, ok := mh.Codes[options.MhType]
43 + if !ok {
44 + return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
45 + }
46 + req.Option("hash", mht)
47 + }
48 +
49 + err = req.FileBody(src).Exec(ctx, &out)
50 if err != nil {
51 return nil, err
52 }
@@ -56,7 +58,7 @@ func (api *DagAPI) Get(ctx context.Context, path iface.Path) (format.Node, error
58 panic("implement me")
59 }
60
59 -func (api *DagAPI) Tree(ctx context.Context, path iface.Path, opts ...options.DagTreeOption) ([]iface.Path, error) {
61 +func (api *DagAPI) Tree(ctx context.Context, path iface.Path, opts ...caopts.DagTreeOption) ([]iface.Path, error) {
62 panic("implement me")
63 }
64