From a41e498d3ae27db6add12ae633312260dcea72e1 Mon Sep 17 00:00:00 2001 From: Nato Boram Date: Thu, 4 Apr 2019 18:19:19 -0400 Subject: [PATCH] added a field to check a specific hash --- app.js | 99 +++++++++++++++++++++++++++++------------------------- index.html | 42 +++++++++++++++-------- lastpubver | 2 +- 3 files changed, 82 insertions(+), 61 deletions(-) diff --git a/app.js b/app.js index 2bef5f6..c81f1e1 100644 --- a/app.js +++ b/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 '' + gateway + '' +function returnHtmlLink(gateway) { + let gatewayTitle = gateway.split(hashToTest)[0]; + return '' + gateway + ''; } -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)); +} diff --git a/index.html b/index.html index f689171..a81cae9 100644 --- a/index.html +++ b/index.html @@ -1,29 +1,43 @@ + Public IPFS Gateways + + +

Public IPFS Gateways

+ + +

+ IPFS Hash : + + +

+

- - + + \ No newline at end of file diff --git a/lastpubver b/lastpubver index 3a8983a..81f3ce9 100644 --- a/lastpubver +++ b/lastpubver @@ -1 +1 @@ -QmUxjqLDYDVnyhaqVCyzSF6gv9FA43opH5WBxkucBBFKYy +QmQyxyStoq1EeiPufeB1FHJ9kMKdWEQFki8pM1dTW3r7ed