Skip to content

Commit

Permalink
use encoder for resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Aug 21, 2023
1 parent d4aea77 commit b5b6759
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion core/commands/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"time"

ns "github.com/ipfs/boxo/namesys"
"github.com/ipfs/boxo/path"
cidenc "github.com/ipfs/go-cidutil/cidenc"
cmdenv "github.com/ipfs/kubo/core/commands/cmdenv"
"github.com/ipfs/kubo/core/commands/cmdutils"
ncmd "github.com/ipfs/kubo/core/commands/name"
Expand Down Expand Up @@ -109,6 +111,23 @@ Resolve the value of an IPFS DAG path:
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: p})
}

var enc cidenc.Encoder
switch {
case !cmdenv.CidBaseDefined(req) && !strings.HasPrefix(name, "/ipns/"):
// Not specified, check the path.
enc, err = cmdenv.CidEncoderFromPath(name)
if err == nil {
break
}
// Nope, fallback on the default.
fallthrough
default:
enc, err = cmdenv.GetCidEncoder(req)
if err != nil {
return err
}
}

p, err := cmdutils.PathOrCidPath(name)
if err != nil {
return err
Expand All @@ -120,7 +139,17 @@ Resolve the value of an IPFS DAG path:
return err
}

return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: rp})
encoded := "/" + rp.Namespace().String() + "/" + enc.Encode(rp.Cid())
if remainder := rp.Remainder(); remainder != "" {
encoded += "/" + remainder
}

rpe, err := path.NewPath(encoded)
if err != nil {
return err
}

return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: rpe})
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, rp *ncmd.ResolvedPath) error {
Expand Down

0 comments on commit b5b6759

Please sign in to comment.