From 84083fe03463b0203b59148572238d00bedeef0d Mon Sep 17 00:00:00 2001 From: Victor Bjelkholm Date: Wed, 27 Sep 2017 22:52:43 +0300 Subject: [PATCH] Restructure + nicer look --- app.js | 48 ++++++++++++++++++++++++++++++ gateways.json | 16 ++++++++++ index.html | 82 +++++++++++++-------------------------------------- 3 files changed, 84 insertions(+), 62 deletions(-) create mode 100644 app.js create mode 100644 gateways.json diff --git a/app.js b/app.js new file mode 100644 index 0000000..b6cee74 --- /dev/null +++ b/app.js @@ -0,0 +1,48 @@ +const hashToTest = 'Qmaisz6NMhDB51cCvNWa1GMS7LU1pAxdF4Ld6Ft9kZEP2a' +const hashString = 'Hello from IPFS Gateway Checker' + +const $results = document.querySelector('#results') + +function addNode (gateway, online, title) { + const para = document.createElement('div') + let node + if (online) { + node = document.createElement('strong') + node.innerText = '✅ - Online - ' + 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 checkGateways (gateways) { + const total = gateways.length + let checked = 0 + gateways.forEach((gateway) => { + const gatewayAndHash = gateway.replace(':hash', hashToTest) + fetch(gatewayAndHash) + .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) + }) + }) +} + +fetch('./gateways.json') + .then(res => res.json()) + .then(gateways => checkGateways(gateways)) diff --git a/gateways.json b/gateways.json new file mode 100644 index 0000000..5aa30d9 --- /dev/null +++ b/gateways.json @@ -0,0 +1,16 @@ +[ + "https://ipfs.io/ipfs/:hash", + "https://gateway.ipfs.io/ipfs/:hash", + "https://ipfs.infura.io/ipfs/:hash", + "http://rx14.co.uk/ipfs/:hash", + "https://xmine128.tk/ipfs/:hash", + "https://upload.global/ipfs/:hash", + "https://ipfs.jes.xxx/ipfs/:hash", + "https://catalunya.network/ipfs/:hash", + "https://siderus.io/ipfs/:hash", + "https://eternum.io/ipfs/:hash", + "https://hardbin.com/ipfs/:hash", + "https://ipfs.macholibre.org/ipfs/:hash", + "https://ipfs.works/ipfs/:hash", + "https://ipfs.work/ipfs/:hash" +] diff --git a/index.html b/index.html index 0d696db..f689171 100644 --- a/index.html +++ b/index.html @@ -2,70 +2,28 @@ - + Public IPFS Gateways +

Public IPFS Gateways

-

+

+
- +