2019-04-04 22:19:19 +00:00
|
|
|
var hashToTest = "";
|
2019-04-10 04:37:39 +00:00
|
|
|
var protocol = "";
|
2019-04-04 22:19:19 +00:00
|
|
|
const $results = document.querySelector('#results');
|
2017-09-27 19:52:43 +00:00
|
|
|
|
2019-04-04 22:19:19 +00:00
|
|
|
function returnHtmlLink(gateway) {
|
|
|
|
let gatewayTitle = gateway.split(hashToTest)[0];
|
|
|
|
return '<a title="' + gatewayTitle + '" href="' + gateway + '">' + gateway + '</a>';
|
2019-03-03 02:31:03 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 22:19:19 +00:00
|
|
|
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);
|
2017-09-27 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 22:19:19 +00:00
|
|
|
function updateStats(total, checked) {
|
|
|
|
document.getElementById('stats').innerText = checked + '/' + total + ' gateways checked';
|
2017-09-27 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 22:19:19 +00:00
|
|
|
function checkGateways(gateways) {
|
|
|
|
const total = gateways.length;
|
|
|
|
let checked = 0;
|
|
|
|
gateways.forEach((gateway) => {
|
2019-04-10 04:37:39 +00:00
|
|
|
gateway = gateway.replace('/ipfs/', protocol);
|
2019-04-04 22:19:19 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2017-09-27 19:52:43 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 04:37:39 +00:00
|
|
|
function start_ipfs() {
|
2019-04-04 22:19:19 +00:00
|
|
|
|
|
|
|
while ($results.lastChild) {
|
|
|
|
$results.removeChild($results.lastChild);
|
|
|
|
}
|
|
|
|
|
2019-04-10 04:37:39 +00:00
|
|
|
hashToTest = document.querySelector("#input_ipfs").value;
|
|
|
|
protocol = "/ipfs/";
|
|
|
|
|
|
|
|
fetch('./json/gateways.json')
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(gateways => checkGateways(gateways));
|
|
|
|
}
|
|
|
|
|
|
|
|
function start_ipns() {
|
|
|
|
|
|
|
|
while ($results.lastChild) {
|
|
|
|
$results.removeChild($results.lastChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
hashToTest = document.querySelector("#input_ipns").value;
|
|
|
|
protocol = "/ipns/";
|
2019-04-04 22:19:19 +00:00
|
|
|
|
2019-04-04 23:12:27 +00:00
|
|
|
fetch('./json/gateways.json')
|
2019-04-04 22:19:19 +00:00
|
|
|
.then(res => res.json())
|
|
|
|
.then(gateways => checkGateways(gateways));
|
|
|
|
}
|