mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-01 22:37:51 +08:00
HTTP Gateway: add /ipns/ GET requests
This commit is contained in:
parent
7d09da3c8b
commit
295cc443da
@ -13,7 +13,7 @@ func GatewayOption(writable bool) ServeOption {
|
||||
return err
|
||||
}
|
||||
mux.Handle("/ipfs/", gateway)
|
||||
mux.Handle("/ipns/", gateway)
|
||||
mux.Handle("/ipns/", gateway)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ func (i *gatewayHandler) loadTemplate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *gatewayHandler) ResolvePath(ctx context.Context, p string) (*dag.Node, string, error) {
|
||||
func (i *gatewayHandler) resolveNamePath(ctx context.Context, p string) (string, error) {
|
||||
p = gopath.Clean(p)
|
||||
|
||||
if strings.HasPrefix(p, IpnsPathPrefix) {
|
||||
@ -83,7 +83,7 @@ func (i *gatewayHandler) ResolvePath(ctx context.Context, p string) (*dag.Node,
|
||||
hash := elements[0]
|
||||
k, err := i.node.Namesys.Resolve(ctx, hash)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
return "", err
|
||||
}
|
||||
|
||||
elements[0] = k.Pretty()
|
||||
@ -92,6 +92,14 @@ func (i *gatewayHandler) ResolvePath(ctx context.Context, p string) (*dag.Node,
|
||||
if !strings.HasPrefix(p, IpfsPathPrefix) {
|
||||
p = gopath.Join(IpfsPathPrefix, p)
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (i *gatewayHandler) ResolvePath(ctx context.Context, p string) (*dag.Node, string, error) {
|
||||
p, err := i.resolveNamePath(ctx, p)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
node, err := i.node.Resolver.ResolvePath(path.Path(p))
|
||||
if err != nil {
|
||||
@ -298,7 +306,17 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
h, components, err := path.SplitAbsPath(path.Path(urlPath))
|
||||
ctx, cancel := context.WithCancel(i.node.Context())
|
||||
defer cancel()
|
||||
|
||||
ipfspath, err := i.resolveNamePath(ctx, urlPath)
|
||||
if err != nil {
|
||||
// FIXME HTTP error code
|
||||
webError(w, "Could not resolve name", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
h, components, err := path.SplitAbsPath(path.Path(ipfspath))
|
||||
if err != nil {
|
||||
webError(w, "Could not split path", err, http.StatusInternalServerError)
|
||||
return
|
||||
@ -358,7 +376,17 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||
urlPath := r.URL.Path
|
||||
h, components, err := path.SplitAbsPath(path.Path(urlPath))
|
||||
ctx, cancel := context.WithCancel(i.node.Context())
|
||||
defer cancel()
|
||||
|
||||
ipfspath, err := i.resolveNamePath(ctx, urlPath)
|
||||
if err != nil {
|
||||
// FIXME HTTP error code
|
||||
webError(w, "Could not resolve name", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
h, components, err := path.SplitAbsPath(path.Path(ipfspath))
|
||||
if err != nil {
|
||||
webError(w, "Could not split path", err, http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
Loading…
Reference in New Issue
Block a user