mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Update to support pathnames on IPFS hash
As @Georgi87 mentioned about pathnames on the domain like `http://phyrextsai.eth/home` will pass to IPFS hash and append `/home` on redirection url. You can try the example below: http://phyrextsai.eth/index.html http://phyrextsai.eth/images/phyrex.jpg
This commit is contained in:
parent
8a571ece36
commit
11736e6318
@ -3,8 +3,12 @@ const resolver = require('./resolver.js')
|
|||||||
|
|
||||||
module.exports = function (provider) {
|
module.exports = function (provider) {
|
||||||
extension.webRequest.onBeforeRequest.addListener(details => {
|
extension.webRequest.onBeforeRequest.addListener(details => {
|
||||||
const name = details.url.substring(7, details.url.length - 1)
|
const urlhttpreplace = details.url.replace(/\w+?:\/\//, "")
|
||||||
|
const url = urlhttpreplace.replace(/[\\\/].*/g, "")
|
||||||
|
let domainhtml = urlhttpreplace.match(/[\\\/].*/g)
|
||||||
let clearTime = null
|
let clearTime = null
|
||||||
|
let 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' })
|
||||||
|
|
||||||
@ -14,13 +18,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
|
let url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0]
|
||||||
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
|
url = 'https://ipfs.infura.io/ipfs/' + ipfsHash + domainhtml[0]
|
||||||
extension.tabs.update(tab.id, {url: url})
|
extension.tabs.update(tab.id, {url: url})
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
@ -32,5 +36,5 @@ module.exports = function (provider) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
return { cancel: true }
|
return { cancel: true }
|
||||||
}, {urls: ['*://*.eth/']})
|
}, {urls: ['*://*.eth/', '*://*.eth/*']})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user