Skip to content

Commit

Permalink
decode multihash string for B58 and Hex
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr committed Jun 18, 2024
1 parent 12dbcff commit 61b3dc7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions server/find/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
indexer "github.com/ipni/go-indexer-core"
"github.com/ipni/go-indexer-core"
coremetrics "github.com/ipni/go-indexer-core/metrics"
"github.com/ipni/go-libipni/apierror"
"github.com/ipni/go-libipni/find/model"
Expand Down Expand Up @@ -179,7 +179,7 @@ func (s *Server) findMultihash(w http.ResponseWriter, r *http.Request) {
stream := match == mediaTypeNDJson

mhVar := path.Base(r.URL.Path)
m, err := multihash.FromB58String(mhVar)
m, err := caseMHString(mhVar)
if err != nil {
log.Errorw("error decoding multihash", "multihash", mhVar, "err", err)
httpserver.HandleError(w, err, "find")
Expand Down Expand Up @@ -516,3 +516,15 @@ func createExtendedProviderResult(epInfo registry.ExtendedProviderInfo, iVal ind
},
}
}

func caseMHString(s string) (multihash.Multihash, error) {
mh, err := multihash.FromHexString(s)
if err != nil {
mh, err := multihash.FromB58String(s)
if err != nil {
return multihash.Multihash{}, err
}
return mh, nil
}
return mh, nil
}

0 comments on commit 61b3dc7

Please sign in to comment.