aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorbitpshr <mail@bitpshr.net>2018-07-16 02:34:48 +0800
committerbitpshr <mail@bitpshr.net>2018-07-19 20:04:17 +0800
commit94f99b6ed0385e90fda07c6ef5b5ceaf654fb666 (patch)
tree9e18eed3941de7f3645d04fe0b960d38c42bc00e /app
parent8df433ca8476e14b08fc95be973283d0200f8458 (diff)
downloadtangerine-wallet-browser-94f99b6ed0385e90fda07c6ef5b5ceaf654fb666.tar
tangerine-wallet-browser-94f99b6ed0385e90fda07c6ef5b5ceaf654fb666.tar.gz
tangerine-wallet-browser-94f99b6ed0385e90fda07c6ef5b5ceaf654fb666.tar.bz2
tangerine-wallet-browser-94f99b6ed0385e90fda07c6ef5b5ceaf654fb666.tar.lz
tangerine-wallet-browser-94f99b6ed0385e90fda07c6ef5b5ceaf654fb666.tar.xz
tangerine-wallet-browser-94f99b6ed0385e90fda07c6ef5b5ceaf654fb666.tar.zst
tangerine-wallet-browser-94f99b6ed0385e90fda07c6ef5b5ceaf654fb666.zip
Updates
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/ipfsContent.js70
1 files changed, 37 insertions, 33 deletions
diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js
index a6b99b2f9..15d25df20 100644
--- a/app/scripts/lib/ipfsContent.js
+++ b/app/scripts/lib/ipfsContent.js
@@ -2,39 +2,43 @@ 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' })
+ function ipfsContent(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)
+ 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/*']})
+ resolver.resolve(name, provider).then(ipfsHash => {
+ clearTimeout(clearTime)
+ let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash
+ 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
+ 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 }
+ }
+
+ extension.webRequest.onBeforeRequest.addListener(ipfsContent, {urls: ['*://*.eth/', '*://*.test/']})
+
+ return {
+ remove () {
+ extension.webRequest.onBeforeRequest.removeListener(ipfsContent)
+ },
+ }
}