added a field to check a specific hash

merge-requests/2/merge
Nato Boram 2019-04-04 18:19:19 -04:00
parent 1bc3d51c8f
commit a41e498d3a
3 changed files with 82 additions and 61 deletions

69
app.js
View File

@ -1,55 +1,62 @@
const hashToTest = 'Qmaisz6NMhDB51cCvNWa1GMS7LU1pAxdF4Ld6Ft9kZEP2a'
const hashString = 'Hello from IPFS Gateway Checker'
const $results = document.querySelector('#results')
var hashToTest = "";
const $results = document.querySelector('#results');
function returnHtmlLink(gateway) {
let gatewayTitle = gateway.split(hashToTest)[0]
return '<a title="' + gatewayTitle + '" href="' + gateway + '">' + gateway + '</a>'
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
const para = document.createElement('div');
let node;
if (online) {
node = document.createElement('strong')
node.innerHTML = '✅ - Online - ' + returnHtmlLink(gateway)
node = document.createElement('strong');
node.innerHTML = '✅ - Online - ' + returnHtmlLink(gateway);
} else {
node = document.createElement('div')
node.innerText = '❌ - Offline - ' + gateway
node = document.createElement('div');
node.innerText = '❌ - Offline - ' + gateway;
}
node.setAttribute('title', title)
para.appendChild(node)
$results.appendChild(para)
node.setAttribute('title', title);
para.appendChild(node);
$results.appendChild(para);
}
function updateStats(total, checked) {
document.getElementById('stats').innerText = checked + '/' + total + ' gateways checked'
document.getElementById('stats').innerText = checked + '/' + total + ' gateways checked';
}
function checkGateways(gateways) {
const total = gateways.length
let checked = 0
const total = gateways.length;
let checked = 0;
gateways.forEach((gateway) => {
const gatewayAndHash = gateway.replace(':hash', hashToTest)
const gatewayAndHash = gateway.replace(':hash', hashToTest);
// opt-out from gateway redirects done by browser extension
const testUrl = gatewayAndHash + '#x-ipfs-companion-no-redirect'
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)
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)
})
})
window.err = err;
addNode(gatewayAndHash, false, err);
checked++;
updateStats(total, checked);
});
});
}
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))
.then(gateways => checkGateways(gateways));
}

View File

@ -1,16 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Public IPFS Gateways</title>
<style>
body, html {
body,
html {
font-family: Verdana, sans-serif;
color: #121212;
background-color: #FAFAFA;
}
h1, h3 {
h1,
h3 {
font-weight: normal;
}
@ -19,11 +22,22 @@
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>

View File

@ -1 +1 @@
QmUxjqLDYDVnyhaqVCyzSF6gv9FA43opH5WBxkucBBFKYy
QmQyxyStoq1EeiPufeB1FHJ9kMKdWEQFki8pM1dTW3r7ed