How to use the is-ipfs.path function in is-ipfs

To help you get started, we’ve selected a few is-ipfs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipfs-shipyard / ipfs-companion / add-on / src / lib / dnslink.js View on Github external
apiProvider = 'https://ipfs.io/'
      }
      // js-ipfs-api does not provide method for fetching this
      // TODO: revisit after https://github.com/ipfs/js-ipfs-api/issues/501 is addressed
      // TODO: consider worst-case-scenario fallback to https://developers.google.com/speed/public-dns/docs/dns-over-https
      const apiCall = `${apiProvider}api/v0/dns/${fqdn}?r=true`
      const xhr = new XMLHttpRequest() // older XHR API us used because window.fetch appends Origin which causes error 403 in go-ipfs
      // synchronous mode with small timeout
      // (it is okay, because we do it only once, then it is cached and read via readAndCacheDnslink)
      xhr.open('GET', apiCall, false)
      xhr.setRequestHeader('Accept', 'application/json')
      xhr.send(null)
      if (xhr.status === 200) {
        const dnslink = JSON.parse(xhr.responseText).Path
        // console.log('readDnslinkFromTxtRecord', readDnslinkFromTxtRecord)
        if (!IsIpfs.path(dnslink)) {
          throw new Error(`dnslink for '${fqdn}' is not a valid IPFS path: '${dnslink}'`)
        }
        return dnslink
      } else if (xhr.status === 500) {
        // go-ipfs returns 500 if host has no dnslink or an error occurred
        // TODO: find/fill an upstream bug to make this more intuitive
        return false
      } else {
        throw new Error(xhr.statusText)
      }
    },
github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-request.js View on Github external
function normalizedUnhandledIpfsProtocol (request, pubGwUrl) {
  let path = unhandledIpfsPath(request.url)
  path = fixupDnslinkPath(path) // /ipfs/example.com → /ipns/example.com
  if (IsIpfs.path(path)) {
    // replace search query with a request to a public gateway
    // (will be redirected later, if needed)
    return { redirectUrl: pathAtHttpGateway(path, pubGwUrl) }
  }
}
github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-request.js View on Github external
function normalizedRedirectingProtocolRequest (request, pubGwUrl) {
  const oldPath = decodeURIComponent(new URL(request.url).hash)
  let path = oldPath
  // prefixed (Firefox < 59)
  path = path.replace(/^#web\+dweb:\//i, '/') // web+dweb:/ipfs/Qm → /ipfs/Qm
  path = path.replace(/^#web\+ipfs:\/\//i, '/ipfs/') // web+ipfs://Qm → /ipfs/Qm
  path = path.replace(/^#web\+ipns:\/\//i, '/ipns/') // web+ipns://Qm → /ipns/Qm
  // without prefix (Firefox >= 59)
  path = path.replace(/^#dweb:\//i, '/') // dweb:/ipfs/Qm → /ipfs/Qm
  path = path.replace(/^#ipfs:\/\//i, '/ipfs/') // ipfs://Qm → /ipfs/Qm
  path = path.replace(/^#ipns:\/\//i, '/ipns/') // ipns://Qm → /ipns/Qm
  // additional fixups of the final path
  path = fixupDnslinkPath(path) // /ipfs/example.com → /ipns/example.com
  if (oldPath !== path && IsIpfs.path(path)) {
    return { redirectUrl: pathAtHttpGateway(path, pubGwUrl) }
  }
  return null
}
github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-path.js View on Github external
function normalizedIpfsPath (urlOrPath) {
  let result = urlOrPath
  // Convert CID-in-subdomain URL to /ipns// path
  if (IsIpfs.subdomain(urlOrPath)) {
    result = subdomainToIpfsPath(urlOrPath)
  }
  // Drop everything before the IPFS path
  result = result.replace(/^.*(\/ip(f|n)s\/.+)$/, '$1')
  // Remove Unescape special characters
  // https://github.com/ipfs/ipfs-companion/issues/303
  result = decodeURIComponent(result)
  // Return a valid IPFS path or null otherwise
  return IsIpfs.path(result) ? result : null
}
exports.normalizedIpfsPath = normalizedIpfsPath
github ipld / js-ipld / src / ipld-service.js View on Github external
function normalizeKey (key) {
  let res
  const isMhash = isIPFS.multihash(key)
  const isPath = isIPFS.path(key)

  if (!isMhash && !isPath) {
    return null
  }

  if (isMhash) {
    res = key
  } else if (isPath) {
    res = key.replace('/ipfs/', '')
  }

  if (typeof res === 'string') {
    return mh.fromB58String(res)
  }

  return res
github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-request.js View on Github external
function unhandledIpfsPath (requestUrl) {
  const unhandled = requestUrl.match(unhandledIpfsRE)
  if (unhandled && unhandled.length > 1) {
    const unhandledProtocol = decodeURIComponent(unhandled[1])
    const unhandledPath = `/${decodeURIComponent(unhandled[2])}`
    return IsIpfs.path(unhandledPath) ? unhandledPath : `/${unhandledProtocol}${unhandledPath}`
  }
  return null
}
github ipfs-shipyard / ipfs-webui / src / files / explore-form / FilesExploreForm.js View on Github external
get isValid () {
    return this.path !== '' && (isIPFS.cid(this.path) || isIPFS.path(this.path))
  }

is-ipfs

A set of utilities to help identify IPFS resources on the web

Apache-2.0 OR MIT
Latest version published 3 months ago

Package Health Score

81 / 100
Full package analysis