@@ -3,30 +3,25 @@ package httpapi
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "github.com/ipfs/go-cid"
7
6
"io"
7
+ "math"
8
8
9
9
"github.com/ipfs/go-ipfs/core/coreapi/interface"
10
- "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11
-
12
10
caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11
+
12
+ "github.com/ipfs/go-cid"
13
13
"github.com/ipfs/go-ipld-format"
14
14
mh "github.com/multiformats/go-multihash"
15
15
)
16
16
17
17
type DagAPI HttpApi
18
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
20
options , err := caopts .DagPutOptions (opts ... )
21
21
if err != nil {
22
22
return nil , err
23
23
}
24
24
25
- mht , ok := mh .Codes [options .MhType ]
26
- if ! ok {
27
- return nil , fmt .Errorf ("unknowm mhType %d" , options .MhType )
28
- }
29
-
30
25
codec , ok := cid .CodecToStr [options .Codec ]
31
26
if ! ok {
32
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
39
34
var out struct {
40
35
Cid cid.Cid
41
36
}
42
- err = api .core ().request ("dht/put" ).
43
- Option ("hash" , mht ).
37
+ req := api .core ().request ("dag/put" ).
44
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 )
48
50
if err != nil {
49
51
return nil , err
50
52
}
@@ -56,7 +58,7 @@ func (api *DagAPI) Get(ctx context.Context, path iface.Path) (format.Node, error
56
58
panic ("implement me" )
57
59
}
58
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 ) {
60
62
panic ("implement me" )
61
63
}
62
64
0 commit comments