added a field to check a specific hash
parent
1bc3d51c8f
commit
a41e498d3a
99
app.js
99
app.js
|
@ -1,55 +1,62 @@
|
|||
const hashToTest = 'Qmaisz6NMhDB51cCvNWa1GMS7LU1pAxdF4Ld6Ft9kZEP2a'
|
||||
const hashString = 'Hello from IPFS Gateway Checker'
|
||||
var hashToTest = "";
|
||||
const $results = document.querySelector('#results');
|
||||
|
||||
const $results = document.querySelector('#results')
|
||||
|
||||
function returnHtmlLink (gateway) {
|
||||
let gatewayTitle = gateway.split(hashToTest)[0]
|
||||
return '<a title="' + gatewayTitle + '" href="' + gateway + '">' + gateway + '</a>'
|
||||
function returnHtmlLink(gateway) {
|
||||
let gatewayTitle = gateway.split(hashToTest)[0];
|
||||
return '<a title="' + gatewayTitle + '" href="' + gateway + '">' + gateway + '</a>';
|
||||
}
|
||||
|
||||
function addNode (gateway, online, title) {
|
||||
const para = document.createElement('div')
|
||||
let node
|
||||
if (online) {
|
||||
node = document.createElement('strong')
|
||||
node.innerHTML = '✅ - Online - ' + returnHtmlLink(gateway)
|
||||
} else {
|
||||
node = document.createElement('div')
|
||||
node.innerText = '❌ - Offline - ' + gateway
|
||||
}
|
||||
node.setAttribute('title', title)
|
||||
para.appendChild(node)
|
||||
$results.appendChild(para)
|
||||
function addNode(gateway, online, title) {
|
||||
const para = document.createElement('div');
|
||||
let node;
|
||||
if (online) {
|
||||
node = document.createElement('strong');
|
||||
node.innerHTML = '✅ - Online - ' + returnHtmlLink(gateway);
|
||||
} else {
|
||||
node = document.createElement('div');
|
||||
node.innerText = '❌ - Offline - ' + gateway;
|
||||
}
|
||||
node.setAttribute('title', title);
|
||||
para.appendChild(node);
|
||||
$results.appendChild(para);
|
||||
}
|
||||
|
||||
function updateStats (total, checked) {
|
||||
document.getElementById('stats').innerText = checked + '/' + total + ' gateways checked'
|
||||
function updateStats(total, checked) {
|
||||
document.getElementById('stats').innerText = checked + '/' + total + ' gateways checked';
|
||||
}
|
||||
|
||||
function checkGateways (gateways) {
|
||||
const total = gateways.length
|
||||
let checked = 0
|
||||
gateways.forEach((gateway) => {
|
||||
const gatewayAndHash = gateway.replace(':hash', hashToTest)
|
||||
// opt-out from gateway redirects done by browser extension
|
||||
const testUrl = gatewayAndHash + '#x-ipfs-companion-no-redirect'
|
||||
fetch(testUrl)
|
||||
.then(res => res.text())
|
||||
.then((text) => {
|
||||
const matched = text.trim() === hashString.trim()
|
||||
addNode(gatewayAndHash, matched, matched ? 'All good' : 'Output did not match expected output')
|
||||
checked++
|
||||
updateStats(total, checked)
|
||||
}).catch((err) => {
|
||||
window.err = err
|
||||
addNode(gatewayAndHash, false, err)
|
||||
checked++
|
||||
updateStats(total, checked)
|
||||
})
|
||||
})
|
||||
function checkGateways(gateways) {
|
||||
const total = gateways.length;
|
||||
let checked = 0;
|
||||
gateways.forEach((gateway) => {
|
||||
const gatewayAndHash = gateway.replace(':hash', hashToTest);
|
||||
// opt-out from gateway redirects done by browser extension
|
||||
const testUrl = gatewayAndHash + '#x-ipfs-companion-no-redirect';
|
||||
fetch(testUrl)
|
||||
.then(res => res.text())
|
||||
.then((text) => {
|
||||
const matched = true; // TODO : Check if the response is good.
|
||||
addNode(gatewayAndHash, matched, matched ? 'All good' : 'Output did not match expected output');
|
||||
checked++;
|
||||
updateStats(total, checked);
|
||||
}).catch((err) => {
|
||||
window.err = err;
|
||||
addNode(gatewayAndHash, false, err);
|
||||
checked++;
|
||||
updateStats(total, checked);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fetch('./gateways.json')
|
||||
.then(res => res.json())
|
||||
.then(gateways => checkGateways(gateways))
|
||||
function start() {
|
||||
|
||||
while ($results.lastChild) {
|
||||
$results.removeChild($results.lastChild);
|
||||
}
|
||||
|
||||
hashToTest = document.querySelector("#input").value;
|
||||
|
||||
fetch('./gateways.json')
|
||||
.then(res => res.json())
|
||||
.then(gateways => checkGateways(gateways));
|
||||
}
|
||||
|
|
40
index.html
40
index.html
|
@ -1,29 +1,43 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Public IPFS Gateways</title>
|
||||
<style>
|
||||
body, html {
|
||||
font-family: Verdana, sans-serif;
|
||||
color: #121212;
|
||||
background-color: #FAFAFA;
|
||||
}
|
||||
body,
|
||||
html {
|
||||
font-family: Verdana, sans-serif;
|
||||
color: #121212;
|
||||
background-color: #FAFAFA;
|
||||
}
|
||||
|
||||
h1, h3 {
|
||||
font-weight: normal;
|
||||
}
|
||||
h1,
|
||||
h3 {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
#results {
|
||||
font-family: "SourceCodePro", monospace;
|
||||
white-space: pre;
|
||||
}
|
||||
#results {
|
||||
font-family: "SourceCodePro", monospace;
|
||||
white-space: pre;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script async src="./app.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Public IPFS Gateways</h1>
|
||||
|
||||
<!-- IPFS Hash -->
|
||||
<p>
|
||||
IPFS Hash :
|
||||
<input type="text" name="hash" id="input">
|
||||
<button onclick="start();">Submit</button>
|
||||
</p>
|
||||
|
||||
<h3 id="stats"></h3>
|
||||
<div id="results"></div>
|
||||
</body>
|
||||
<script src="./app.js"></script>
|
||||
|
||||
</html>
|
|
@ -1 +1 @@
|
|||
QmUxjqLDYDVnyhaqVCyzSF6gv9FA43opH5WBxkucBBFKYy
|
||||
QmQyxyStoq1EeiPufeB1FHJ9kMKdWEQFki8pM1dTW3r7ed
|
||||
|
|
Loading…
Reference in New Issue