aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/ipfsContent.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/lib/ipfsContent.js')
-rw-r--r--app/scripts/lib/ipfsContent.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js
new file mode 100644
index 00000000..4d66745e
--- /dev/null
+++ b/app/scripts/lib/ipfsContent.js
@@ -0,0 +1,36 @@
+const extension = require('extensionizer')
+const resolver = require('./resolver.js')
+
+module.exports = function (provider) {
+ extension.webRequest.onBeforeRequest.addListener(details => {
+ const name = details.url.substring(7, details.url.length - 1)
+ let clearTime = null
+ extension.tabs.getSelected(null, tab => {
+ extension.tabs.update(tab.id, { url: 'loading.html' })
+
+ clearTime = setTimeout(() => {
+ return extension.tabs.update(tab.id, { url: '404.html' })
+ }, 60000)
+
+ resolver.resolve(name, provider).then(ipfsHash => {
+ clearTimeout(clearTime)
+ let url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash
+ return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => {
+ if (statusCode !== 200) return 'Local'
+ extension.tabs.update(tab.id, { url: url })
+ })
+ .catch(err => {
+ url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash
+ extension.tabs.update(tab.id, {url: url})
+ return err
+ })
+ })
+ .catch(err => {
+ clearTimeout(clearTime)
+ const url = err === 'unsupport' ? 'unsupport' : 'error'
+ extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`})
+ })
+ })
+ return { cancel: true }
+ }, {urls: ['*://*.eth/']})
+}
> * - Updated to 2.5 (no functional change)Greg Larkin2010-09-162-5/+6 * - update to 1.4.1Dirk Meyer2010-03-281-1/+1 * - update to jpeg-8Dirk Meyer2010-02-051-0/+1 * - Switch SourceForge ports to the new File Release System: categories startin...Dmitry Marakasov2009-08-221-2/+1 * Changed my MAINTAINER address toGreg Larkin2008-07-191-1/+1