Skip to content

Commit

Permalink
Accept a CID or a multihash to lookup
Browse files Browse the repository at this point in the history
Closes #67
  • Loading branch information
gammazero committed Sep 19, 2024
1 parent 6e3c677 commit 27df281
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
"github.com/multiformats/go-multicodec"
"github.com/multiformats/go-multihash"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -108,8 +110,15 @@ func startServer(ctx context.Context, d *daemon, tcpListener, metricsUsername, m
}
cidKey, err := cid.Decode(cidStr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
mh, mhErr := multihash.FromB58String(cidStr)
if mhErr != nil {
mh, mhErr = multihash.FromHexString(cidStr)
if mhErr != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return

Check warning on line 118 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L113-L118

Added lines #L113 - L118 were not covered by tests
}
}
cidKey = cid.NewCidV1(uint64(multicodec.Cidv1), mh)

Check warning on line 121 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L121

Added line #L121 was not covered by tests
}

checkTimeout := defaultCheckTimeout
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 class="dib pa3 ma0 lh-tight">
</section>
<section class="bg-near-white">
<form id="queryForm" class="mw8 center lh-copy dark-gray br2 pv4 ph2 ph4-ns">
<label class="db mt3 f6 fw6" for="cid">CID</label>
<label class="db mt3 f6 fw6" for="cid">CID or multihash</label>
<input class="db w-100 pa2" type="text" id="cid" name="cid" required>
<label class="db mt3 f6 fw6" for="ma">Multiaddr (optional)</label>
<input class="db w-100 pa2" type="text" id="multiaddr" name="multiaddr" placeholder="/p2p/12D3Koo..." />
Expand Down

0 comments on commit 27df281

Please sign in to comment.