diff options
author | Анна <anna@MacBook-Air-Anna.local> | 2018-07-05 11:15:28 +0800 |
---|---|---|
committer | Анна <anna@MacBook-Air-Anna.local> | 2018-07-05 11:15:28 +0800 |
commit | 90934bca46cf990554cbf9be9e302ab5e2fc8041 (patch) | |
tree | ee68fa3d98e8c0e072980fd07397b3a9bd40d640 /app/scripts/lib/ipfsContent.js | |
parent | 1f6bf0a80d43252d7b84e8e0247a524b77569810 (diff) | |
parent | fd218142acb6dab0b2f921b9729f17ff90cffc2d (diff) | |
download | tangerine-wallet-browser-90934bca46cf990554cbf9be9e302ab5e2fc8041.tar tangerine-wallet-browser-90934bca46cf990554cbf9be9e302ab5e2fc8041.tar.gz tangerine-wallet-browser-90934bca46cf990554cbf9be9e302ab5e2fc8041.tar.bz2 tangerine-wallet-browser-90934bca46cf990554cbf9be9e302ab5e2fc8041.tar.lz tangerine-wallet-browser-90934bca46cf990554cbf9be9e302ab5e2fc8041.tar.xz tangerine-wallet-browser-90934bca46cf990554cbf9be9e302ab5e2fc8041.tar.zst tangerine-wallet-browser-90934bca46cf990554cbf9be9e302ab5e2fc8041.zip |
Merge branch 'develop' into to-autocomplete
Diffstat (limited to 'app/scripts/lib/ipfsContent.js')
-rw-r--r-- | app/scripts/lib/ipfsContent.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js new file mode 100644 index 000000000..a6b99b2f9 --- /dev/null +++ b/app/scripts/lib/ipfsContent.js @@ -0,0 +1,40 @@ +const extension = require('extensionizer') +const resolver = require('./resolver.js') + +module.exports = function (provider) { + extension.webRequest.onBeforeRequest.addListener(details => { + const urlhttpreplace = details.url.replace(/\w+?:\/\//, '') + const url = urlhttpreplace.replace(/[\\/].*/g, '') // eslint-disable-line no-useless-escape + let domainhtml = urlhttpreplace.match(/[\\/].*/g) // eslint-disable-line no-useless-escape + let clearTime = null + const name = url.replace(/\/$/g, '') + if (domainhtml === null) domainhtml = [''] + 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://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0] + return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => { + if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' }) + extension.tabs.update(tab.id, { url: url }) + }) + .catch(err => { + url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0] + 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/', '*://*.eth/*']}) +} |