|
|
@ -26,22 +26,22 @@ function setupEnsIpfsResolver ({ provider }) { |
|
|
|
if (tabId === -1) return |
|
|
|
if (tabId === -1) return |
|
|
|
// parse ens name
|
|
|
|
// parse ens name
|
|
|
|
const urlData = urlUtil.parse(url) |
|
|
|
const urlData = urlUtil.parse(url) |
|
|
|
const { hostname: name, path, search } = urlData |
|
|
|
const { hostname: name, path, search, hash: fragment } = urlData |
|
|
|
const domainParts = name.split('.') |
|
|
|
const domainParts = name.split('.') |
|
|
|
const topLevelDomain = domainParts[domainParts.length - 1] |
|
|
|
const topLevelDomain = domainParts[domainParts.length - 1] |
|
|
|
// if unsupported TLD, abort
|
|
|
|
// if unsupported TLD, abort
|
|
|
|
if (!supportedTopLevelDomains.includes(topLevelDomain)) return |
|
|
|
if (!supportedTopLevelDomains.includes(topLevelDomain)) return |
|
|
|
// otherwise attempt resolve
|
|
|
|
// otherwise attempt resolve
|
|
|
|
attemptResolve({ tabId, name, path, search }) |
|
|
|
attemptResolve({ tabId, name, path, search, fragment }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function attemptResolve ({ tabId, name, path, search }) { |
|
|
|
async function attemptResolve ({ tabId, name, path, search, fragment }) { |
|
|
|
extension.tabs.update(tabId, { url: `loading.html` }) |
|
|
|
extension.tabs.update(tabId, { url: `loading.html` }) |
|
|
|
let url = `https://manager.ens.domains/name/${name}` |
|
|
|
let url = `https://app.ens.domains/name/${name}` |
|
|
|
try { |
|
|
|
try { |
|
|
|
const {type, hash} = await resolveEnsToIpfsContentId({ provider, name }) |
|
|
|
const {type, hash} = await resolveEnsToIpfsContentId({ provider, name }) |
|
|
|
if (type === 'ipfs-ns') { |
|
|
|
if (type === 'ipfs-ns') { |
|
|
|
const resolvedUrl = `https://gateway.ipfs.io/ipfs/${hash}${path}${search || ''}` |
|
|
|
const resolvedUrl = `https://gateway.ipfs.io/ipfs/${hash}${path}${search || ''}${fragment || ''}` |
|
|
|
try { |
|
|
|
try { |
|
|
|
// check if ipfs gateway has result
|
|
|
|
// check if ipfs gateway has result
|
|
|
|
const response = await fetch(resolvedUrl, { method: 'HEAD' }) |
|
|
|
const response = await fetch(resolvedUrl, { method: 'HEAD' }) |
|
|
@ -50,11 +50,11 @@ function setupEnsIpfsResolver ({ provider }) { |
|
|
|
console.warn(err) |
|
|
|
console.warn(err) |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (type === 'swarm-ns') { |
|
|
|
} else if (type === 'swarm-ns') { |
|
|
|
url = `https://swarm-gateways.net/bzz:/${hash}${path}${search || ''}` |
|
|
|
url = `https://swarm-gateways.net/bzz:/${hash}${path}${search || ''}${fragment || ''}` |
|
|
|
} else if (type === 'onion' || type === 'onion3') { |
|
|
|
} else if (type === 'onion' || type === 'onion3') { |
|
|
|
url = `http://${hash}.onion${path}${search || ''}` |
|
|
|
url = `http://${hash}.onion${path}${search || ''}${fragment || ''}` |
|
|
|
} else if (type === 'zeronet') { |
|
|
|
} else if (type === 'zeronet') { |
|
|
|
url = `http://127.0.0.1:43110/${hash}${path}${search || ''}` |
|
|
|
url = `http://127.0.0.1:43110/${hash}${path}${search || ''}${fragment || ''}` |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
} catch (err) { |
|
|
|
console.warn(err) |
|
|
|
console.warn(err) |
|
|
|