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

Commit 5b2c99a

Browse files
committed
Fix Dag.Put
1 parent 60321ed commit 5b2c99a

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

dag.go

+17-15
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,25 @@ package httpapi
33
import (
44
"context"
55
"fmt"
6-
"github.com/ipfs/go-cid"
76
"io"
7+
"math"
88

99
"github.com/ipfs/go-ipfs/core/coreapi/interface"
10-
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11-
1210
caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11+
12+
"github.com/ipfs/go-cid"
1313
"github.com/ipfs/go-ipld-format"
1414
mh "github.com/multiformats/go-multihash"
1515
)
1616

1717
type DagAPI HttpApi
1818

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) {
2020
options, err := caopts.DagPutOptions(opts...)
2121
if err != nil {
2222
return nil, err
2323
}
2424

25-
mht, ok := mh.Codes[options.MhType]
26-
if !ok {
27-
return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
28-
}
29-
3025
codec, ok := cid.CodecToStr[options.Codec]
3126
if !ok {
3227
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
3934
var out struct{
4035
Cid cid.Cid
4136
}
42-
err = api.core().request("dht/put").
43-
Option("hash", mht).
37+
req := api.core().request("dag/put").
4438
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)
4850
if err != nil {
4951
return nil, err
5052
}
@@ -56,7 +58,7 @@ func (api *DagAPI) Get(ctx context.Context, path iface.Path) (format.Node, error
5658
panic("implement me")
5759
}
5860

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) {
6062
panic("implement me")
6163
}
6264

0 commit comments

Comments
 (0)