mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 19:24:14 +08:00
address comments from CR
This commit is contained in:
@ -107,9 +107,15 @@ Publish an <ipfs-path> to another public key (not implemented):
|
|||||||
}
|
}
|
||||||
|
|
||||||
func publish(n *core.IpfsNode, k crypto.PrivKey, ref path.Path) (*IpnsEntry, error) {
|
func publish(n *core.IpfsNode, k crypto.PrivKey, ref path.Path) (*IpnsEntry, error) {
|
||||||
|
// First, verify the path exists
|
||||||
|
_, err := n.Resolver.ResolvePath(ref)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
pub := nsys.NewRoutingPublisher(n.Routing)
|
pub := nsys.NewRoutingPublisher(n.Routing)
|
||||||
|
|
||||||
err := pub.Publish(n.Context(), k, ref)
|
err = pub.Publish(n.Context(), k, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ func IPNSHostnameOption() ServeOption {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
host := strings.SplitN(r.Host, ":", 2)[0]
|
host := strings.SplitN(r.Host, ":", 2)[0]
|
||||||
if k, err := n.Namesys.Resolve(ctx, host); err == nil {
|
if p, err := n.Namesys.Resolve(ctx, host); err == nil {
|
||||||
r.URL.Path = "/ipfs/" + k.String() + r.URL.Path
|
r.URL.Path = "/ipfs/" + p.String() + r.URL.Path
|
||||||
}
|
}
|
||||||
childMux.ServeHTTP(w, r)
|
childMux.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
17
path/path.go
17
path/path.go
@ -49,11 +49,13 @@ func FromSegments(seg ...string) Path {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ParsePath(txt string) (Path, error) {
|
func ParsePath(txt string) (Path, error) {
|
||||||
kp, err := ParseKeyToPath(txt)
|
|
||||||
if err == nil {
|
|
||||||
return kp, nil
|
|
||||||
}
|
|
||||||
parts := strings.Split(txt, "/")
|
parts := strings.Split(txt, "/")
|
||||||
|
if len(parts) == 1 {
|
||||||
|
kp, err := ParseKeyToPath(txt)
|
||||||
|
if err == nil {
|
||||||
|
return kp, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(parts) < 3 {
|
if len(parts) < 3 {
|
||||||
return "", ErrBadPath
|
return "", ErrBadPath
|
||||||
}
|
}
|
||||||
@ -66,7 +68,7 @@ func ParsePath(txt string) (Path, error) {
|
|||||||
return "", ErrBadPath
|
return "", ErrBadPath
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ParseKeyToPath(parts[2])
|
_, err := ParseKeyToPath(parts[2])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -86,3 +88,8 @@ func ParseKeyToPath(txt string) (Path, error) {
|
|||||||
}
|
}
|
||||||
return FromKey(u.Key(chk)), nil
|
return FromKey(u.Key(chk)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Path) IsValid() error {
|
||||||
|
_, err := ParsePath(p.String())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user