feature/default_network_editable
bitpshr 6 years ago
parent 8df433ca84
commit 94f99b6ed0
  1. 22
      app/scripts/lib/ipfsContent.js

@ -2,13 +2,9 @@ const extension = require('extensionizer')
const resolver = require('./resolver.js') const resolver = require('./resolver.js')
module.exports = function (provider) { module.exports = function (provider) {
extension.webRequest.onBeforeRequest.addListener(details => { function ipfsContent(details) {
const urlhttpreplace = details.url.replace(/\w+?:\/\//, '') const name = details.url.substring(7, details.url.length - 1)
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 let clearTime = null
const name = url.replace(/\/$/g, '')
if (domainhtml === null) domainhtml = ['']
extension.tabs.getSelected(null, tab => { extension.tabs.getSelected(null, tab => {
extension.tabs.update(tab.id, { url: 'loading.html' }) extension.tabs.update(tab.id, { url: 'loading.html' })
@ -18,13 +14,13 @@ module.exports = function (provider) {
resolver.resolve(name, provider).then(ipfsHash => { resolver.resolve(name, provider).then(ipfsHash => {
clearTimeout(clearTime) clearTimeout(clearTime)
let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0] let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash
return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => { return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => {
if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' }) if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' })
extension.tabs.update(tab.id, { url: url }) extension.tabs.update(tab.id, { url: url })
}) })
.catch(err => { .catch(err => {
url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0] url = 'https://ipfs.infura.io/ipfs/' + ipfsHash
extension.tabs.update(tab.id, {url: url}) extension.tabs.update(tab.id, {url: url})
return err return err
}) })
@ -36,5 +32,13 @@ module.exports = function (provider) {
}) })
}) })
return { cancel: true } return { cancel: true }
}, {urls: ['*://*.eth/', '*://*.eth/*']}) }
extension.webRequest.onBeforeRequest.addListener(ipfsContent, {urls: ['*://*.eth/', '*://*.test/']})
return {
remove () {
extension.webRequest.onBeforeRequest.removeListener(ipfsContent)
},
}
} }

Loading…
Cancel
Save