提交 89e1d9fd 作者: Steven Allen

switch urlstore to the new commands lib

License: MIT
Signed-off-by: 's avatarSteven Allen <steven@stebalien.com>
上级 0349d9de
...@@ -136,7 +136,7 @@ var rootSubcommands = map[string]*cmds.Command{ ...@@ -136,7 +136,7 @@ var rootSubcommands = map[string]*cmds.Command{
"tar": lgc.NewCommand(TarCmd), "tar": lgc.NewCommand(TarCmd),
"file": lgc.NewCommand(unixfs.UnixFSCmd), "file": lgc.NewCommand(unixfs.UnixFSCmd),
"update": lgc.NewCommand(ExternalBinary()), "update": lgc.NewCommand(ExternalBinary()),
"urlstore": lgc.NewCommand(urlStoreCmd), "urlstore": urlStoreCmd,
"version": lgc.NewCommand(VersionCmd), "version": lgc.NewCommand(VersionCmd),
"shutdown": lgc.NewCommand(daemonShutdownCmd), "shutdown": lgc.NewCommand(daemonShutdownCmd),
} }
......
...@@ -4,13 +4,12 @@ import ( ...@@ -4,13 +4,12 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"strings"
cmds "github.com/ipfs/go-ipfs/commands"
filestore "github.com/ipfs/go-ipfs/filestore" filestore "github.com/ipfs/go-ipfs/filestore"
balanced "github.com/ipfs/go-ipfs/importer/balanced" balanced "github.com/ipfs/go-ipfs/importer/balanced"
ihelper "github.com/ipfs/go-ipfs/importer/helpers" ihelper "github.com/ipfs/go-ipfs/importer/helpers"
cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash" mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
chunk "gx/ipfs/QmXnzH7wowyLZy8XJxxaQCVTgLMcDXdMBznmsrmQWCyiQV/go-ipfs-chunker" chunk "gx/ipfs/QmXnzH7wowyLZy8XJxxaQCVTgLMcDXdMBznmsrmQWCyiQV/go-ipfs-chunker"
cid "gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid" cid "gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
...@@ -18,7 +17,6 @@ import ( ...@@ -18,7 +17,6 @@ import (
) )
var urlStoreCmd = &cmds.Command{ var urlStoreCmd = &cmds.Command{
Subcommands: map[string]*cmds.Command{ Subcommands: map[string]*cmds.Command{
"add": urlAdd, "add": urlAdd,
}, },
...@@ -49,9 +47,9 @@ time. ...@@ -49,9 +47,9 @@ time.
}, },
Type: BlockStat{}, Type: BlockStat{},
Run: func(req cmds.Request, res cmds.Response) { Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
url := req.Arguments()[0] url := req.Arguments[0]
n, err := req.InvocContext().GetNode() n, err := GetNode(env)
if err != nil { if err != nil {
res.SetError(err, cmdkit.ErrNormal) res.SetError(err, cmdkit.ErrNormal)
return return
...@@ -106,17 +104,15 @@ time. ...@@ -106,17 +104,15 @@ time.
return return
} }
res.SetOutput(BlockStat{ cmds.EmitOnce(res, BlockStat{
Key: blc.Cid().String(), Key: blc.Cid().String(),
Size: int(hres.ContentLength), Size: int(hres.ContentLength),
}) })
}, },
Marshalers: cmds.MarshalerMap{ Encoders: cmds.EncoderMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) { cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, bs *BlockStat) error {
ch := res.Output().(<-chan interface{}) _, err := fmt.Fprintln(w, bs.Key)
bs0 := <-ch return err
bs := bs0.(*BlockStat) }),
return strings.NewReader(bs.Key + "\n"), nil
},
}, },
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论