How to use the is-ipfs.subdomain 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 / 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 ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-path.js View on Github external
ipfsOrIpnsSubdomain (url) {
      return IsIpfs.subdomain(url)
    },
    // Test if actions such as 'copy URL', 'pin/unpin' should be enabled for the URL
github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-path.js View on Github external
resolveToPublicSubdomainUrl (url, optionalGatewayUrl) {
      // if non-subdomain return as-is
      if (!IsIpfs.subdomain(url)) return url

      const gateway = optionalGatewayUrl || getState().pubSubdomainGwURL
      return redirectSubdomainGateway(url, gateway)
    },
github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-request.js View on Github external
function isSafeToRedirect (request, runtime) {
  // Do not redirect if URL includes opt-out hint
  if (request.url.includes('x-ipfs-companion-no-redirect')) {
    return false
  }

  // For now we do not redirect if cid-in-subdomain is used
  // as it would break origin-based security perimeter
  if (IsIpfs.subdomain(request.url)) {
    return false
  }

  // Ignore XHR requests for which redirect would fail due to CORS bug in Firefox
  // See: https://github.com/ipfs-shipyard/ipfs-companion/issues/436
  if (runtime.requiresXHRCORSfix && request.type === 'xmlhttprequest' && !request.responseHeaders) {
    // Sidenote on XHR Origin: Firefox 60 uses request.originUrl, Chrome 63 uses request.initiator
    if (request.originUrl) {
      const sourceOrigin = new URL(request.originUrl).origin
      const targetOrigin = new URL(request.url).origin
      if (sourceOrigin !== targetOrigin) {
        log('Delaying redirect of CORS XHR until onHeadersReceived due to https://github.com/ipfs-shipyard/ipfs-companion/issues/436 :', request.url)
        onHeadersReceivedRedirect.add(request.requestId)
        return false
      }
    }
github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-path.js View on Github external
resolveToPublicUrl (urlOrPath, optionalGatewayUrl) {
      const input = urlOrPath
      // CID-in-subdomain is good as-is
      if (IsIpfs.subdomain(input)) return input
      // IPFS Paths should be attached to the public gateway
      const ipfsPath = normalizedIpfsPath(input)
      const gateway = optionalGatewayUrl || getState().pubGwURLString
      if (ipfsPath) return pathAtHttpGateway(ipfsPath, gateway)
      // Return original URL (eg. DNSLink domains) or null if not an URL
      return input.startsWith('http') ? input : null
    },
    // Resolve URL or path to subdomain gateway
github ipfs-shipyard / ipfs-companion / add-on / src / lib / ipfs-path.js View on Github external
isIpfsPageActionsContext (url) {
      return Boolean(url && !url.startsWith(getState().apiURLString) && (
        IsIpfs.url(url) ||
        IsIpfs.subdomain(url) ||
        dnslinkResolver.cachedDnslink(new URL(url).hostname)
      ))
    },

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