Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: accept a CID or a multihash to lookup #68

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
"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 +109,15 @@
}
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 117 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L112-L117

Added lines #L112 - L117 were not covered by tests
}
}
cidKey = cid.NewCidV1(cid.Raw, mh)

Check warning on line 120 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L120

Added line #L120 was not covered by tests
}

checkTimeout := defaultCheckTimeout
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -273,7 +273,7 @@ <h2 class="f4">What does it mean if I get an error?</h2>
outText += "IPNI\n"
}
} else {
outText += "❌ Could not find the multihash in DHR or IPNI\n"
outText += "❌ Could not find the multihash in DHT or IPNI\n"
}

if (respObj.DataAvailableOverBitswap.Error !== "") {
Expand Down
Loading