Object.New
This commit was moved from ipfs/go-ipfs-http-client@60321ed42fd8f42e964e37ab5e96839fb8fd77b6
Łukasz Magiera committed
Jan 9, 2019 at 09:22 UTC
101910f04ed0575be19efaacb44b1bce73717033
3 files changed
+91
-1
client/httpapi/api.go
+1
-1
@@ -154,7 +154,7 @@ func (api *HttpApi) Pin() iface.PinAPI {
154
}
155
156
func (api *HttpApi) Object() iface.ObjectAPI {
157
- return nil
157
+ return (*ObjectAPI)(api)
158
}
159
160
func (api *HttpApi) Dht() iface.DhtAPI {
client/httpapi/ipldnode.go
+8
@@ -20,6 +20,14 @@ type ipldNode struct {
20
api *HttpApi
21
}
22
23
+func (a *HttpApi) nodeFromPath(ctx context.Context, p iface.ResolvedPath) ipld.Node {
24
+ return &ipldNode{
25
+ ctx: ctx,
26
+ path: p,
27
+ api: a,
28
+ }
29
+}
30
+
31
func (n *ipldNode) RawData() []byte {
32
r, err := n.api.Block().Get(n.ctx, n.path)
33
if err != nil {
client/httpapi/object.go
new
+82
@@ -0,0 +1,82 @@
1
+package httpapi
2
+
3
+import (
4
+ "context"
5
+ "github.com/ipfs/go-cid"
6
+ "io"
7
+
8
+ "github.com/ipfs/go-ipfs/core/coreapi/interface"
9
+ caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
10
+
11
+ "github.com/ipfs/go-ipld-format"
12
+)
13
+
14
+type ObjectAPI HttpApi
15
+
16
+type objectOut struct {
17
+ Hash string
18
+}
19
+
20
+func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (format.Node, error) {
21
+ options, err := caopts.ObjectNewOptions(opts...)
22
+ if err != nil {
23
+ return nil, err
24
+ }
25
+
26
+ var out objectOut
27
+ err = api.core().request("object/new", options.Type).Exec(ctx, &out)
28
+ if err != nil {
29
+ return nil, err
30
+ }
31
+
32
+ c, err := cid.Parse(out.Hash)
33
+ if err != nil {
34
+ return nil, err
35
+ }
36
+
37
+ return api.core().nodeFromPath(ctx, iface.IpfsPath(c)), nil
38
+}
39
+
40
+func (api *ObjectAPI) Put(context.Context, io.Reader, ...caopts.ObjectPutOption) (iface.ResolvedPath, error) {
41
+ panic("implement me")
42
+}
43
+
44
+func (api *ObjectAPI) Get(context.Context, iface.Path) (format.Node, error) {
45
+ panic("implement me")
46
+}
47
+
48
+func (api *ObjectAPI) Data(context.Context, iface.Path) (io.Reader, error) {
49
+ panic("implement me")
50
+}
51
+
52
+func (api *ObjectAPI) Links(context.Context, iface.Path) ([]*format.Link, error) {
53
+ panic("implement me")
54
+}
55
+
56
+func (api *ObjectAPI) Stat(context.Context, iface.Path) (*iface.ObjectStat, error) {
57
+ panic("implement me")
58
+}
59
+
60
+func (api *ObjectAPI) AddLink(ctx context.Context, base iface.Path, name string, child iface.Path, opts ...caopts.ObjectAddLinkOption) (iface.ResolvedPath, error) {
61
+ panic("implement me")
62
+}
63
+
64
+func (api *ObjectAPI) RmLink(ctx context.Context, base iface.Path, link string) (iface.ResolvedPath, error) {
65
+ panic("implement me")
66
+}
67
+
68
+func (api *ObjectAPI) AppendData(context.Context, iface.Path, io.Reader) (iface.ResolvedPath, error) {
69
+ panic("implement me")
70
+}
71
+
72
+func (api *ObjectAPI) SetData(context.Context, iface.Path, io.Reader) (iface.ResolvedPath, error) {
73
+ panic("implement me")
74
+}
75
+
76
+func (api *ObjectAPI) Diff(context.Context, iface.Path, iface.Path) ([]iface.ObjectChange, error) {
77
+ panic("implement me")
78
+}
79
+
80
+func (api *ObjectAPI) core() *HttpApi {
81
+ return (*HttpApi)(api)
82
+}