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