提交 6a7750d5 作者: Jeromy

fix pin add api break

License: MIT
Signed-off-by: 's avatarJeromy <jeromyj@gmail.com>
上级 60b94a2c
...@@ -31,11 +31,11 @@ var PinCmd = &cmds.Command{ ...@@ -31,11 +31,11 @@ var PinCmd = &cmds.Command{
} }
type PinOutput struct { type PinOutput struct {
Pins []*cid.Cid Pins []string
} }
type AddPinOutput struct { type AddPinOutput struct {
Pins []*cid.Cid Pins []string
Progress int `json:",omitempty"` Progress int `json:",omitempty"`
} }
...@@ -76,7 +76,7 @@ var addPinCmd = &cmds.Command{ ...@@ -76,7 +76,7 @@ var addPinCmd = &cmds.Command{
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return
} }
res.SetOutput(&AddPinOutput{Pins: added}) res.SetOutput(&AddPinOutput{Pins: cidsToStrings(added)})
return return
} }
...@@ -109,7 +109,7 @@ var addPinCmd = &cmds.Command{ ...@@ -109,7 +109,7 @@ var addPinCmd = &cmds.Command{
if pv := v.Value(); pv != 0 { if pv := v.Value(); pv != 0 {
out <- &AddPinOutput{Progress: v.Value()} out <- &AddPinOutput{Progress: v.Value()}
} }
out <- &AddPinOutput{Pins: val} out <- &AddPinOutput{Pins: cidsToStrings(val)}
return return
case <-ticker.C: case <-ticker.C:
out <- &AddPinOutput{Progress: v.Value()} out <- &AddPinOutput{Progress: v.Value()}
...@@ -122,7 +122,7 @@ var addPinCmd = &cmds.Command{ ...@@ -122,7 +122,7 @@ var addPinCmd = &cmds.Command{
}, },
Marshalers: cmds.MarshalerMap{ Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) { cmds.Text: func(res cmds.Response) (io.Reader, error) {
var added []*cid.Cid var added []string
switch out := res.Output().(type) { switch out := res.Output().(type) {
case *AddPinOutput: case *AddPinOutput:
...@@ -203,7 +203,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.) ...@@ -203,7 +203,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
return return
} }
res.SetOutput(&PinOutput{removed}) res.SetOutput(&PinOutput{cidsToStrings(removed)})
}, },
Marshalers: cmds.MarshalerMap{ Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) { cmds.Text: func(res cmds.Response) (io.Reader, error) {
...@@ -413,3 +413,11 @@ func pinLsAll(typeStr string, ctx context.Context, n *core.IpfsNode) (map[string ...@@ -413,3 +413,11 @@ func pinLsAll(typeStr string, ctx context.Context, n *core.IpfsNode) (map[string
return keys, nil return keys, nil
} }
func cidsToStrings(cs []*cid.Cid) []string {
out := make([]string, 0, len(cs))
for _, c := range cs {
out = append(out, c.String())
}
return out
}
...@@ -33,6 +33,19 @@ test_expect_success "metrics work" ' ...@@ -33,6 +33,19 @@ test_expect_success "metrics work" '
test_fsh cat pro_data test_fsh cat pro_data
' '
test_expect_success "pin add api looks right" '
HASH=$(echo "foo" | ipfs add -q) &&
curl "http://$API_ADDR/api/v0/pin/add/$HASH" > pinadd_out &&
echo "{\"Pins\":[\"QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6\"]}" > pinadd_exp &&
test_cmp pinadd_out pinadd_exp
'
test_expect_success "pin add api looks right" '
curl "http://$API_ADDR/api/v0/pin/rm/$HASH" > pinrm_out &&
echo "{\"Pins\":[\"QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6\"]}" > pinrm_exp &&
test_cmp pinrm_out pinrm_exp
'
test_kill_ipfs_daemon test_kill_ipfs_daemon
test_expect_success "ipfs daemon --offline --mount fails - #2995" ' test_expect_success "ipfs daemon --offline --mount fails - #2995" '
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论