How to use the ky-universal.default.get function in ky-universal

To help you get started, we’ve selected a few ky-universal 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 / js-ipfs / src / core / ipns / routing / dns-datastore.js View on Github external
function dohBinary (key, callback) {
  const cid = new Cid(key.slice(ipns.namespaceLength))
  const buf = dnsPacket.encode({
    type: 'query',
    id: getRandomInt(1, 65534),
    flags: dnsPacket.RECURSION_DESIRED,
    questions: [{
      type: 'TXT',
      name: `${cid.toV1().toString()}.dns.ipns.dev`
    }]
  })
  // https://dns.google.com/experimental
  // https://cloudflare-dns.com/dns-query
  // https://mozilla.cloudflare-dns.com/dns-query
  ky
    .get('https://cloudflare-dns.com/dns-query', {
      searchParams: {
        dns: buf.toString('base64')
      },
      headers: {
        accept: 'application/dns-message'
      }
    })
    .arrayBuffer()
    .then(data => {
      data = dnsPacket.decode(Buffer.from(data))
      console.log('TCL: dohBinary -> data', data)

      if (!data && data.answers.length < 1) {
        throw errcode(new Error('Record not found'), 'ERR_NOT_FOUND')
      }
github ipfs / js-ipfs / src / core / runtime / preload-browser.js View on Github external
return httpQueue.add(async () => {
    const res = await ky.get(url, { signal: options.signal })
    const reader = res.body.getReader()

    try {
      while (true) {
        const { done } = await reader.read()
        if (done) return
        // Read to completion but do not cache
      }
    } finally {
      reader.releaseLock()
    }
  })
}
github ipfs / js-ipfs / src / core / runtime / preload-nodejs.js View on Github external
module.exports = async function preload (url, options) {
  log(url)
  options = options || {}

  const res = await ky.get(url, { signal: options.signal })

  for await (const _ of res.body) { // eslint-disable-line no-unused-vars
    // Read to completion but do not cache
  }
}
github ipfs / js-ipfs / src / core / ipns / routing / dns-datastore.js View on Github external
function dohJson (key, callback) {
  const cid = new Cid(key.slice(ipns.namespaceLength))

  // https://dns.google.com/resolve
  // https://cloudflare-dns.com/dns-query
  // https://mozilla.cloudflare-dns.com/dns-query
  ky
    .get('https://cloudflare-dns.com/dns-query', {
      searchParams: {
        name: `${cid.toV1().toString()}.dns.ipns.dev`,
        type: 'TXT',
        cd: 1,
        ad: 0,
        ct: 'application/dns-json'
      }
    })
    .json()
    .then(data => {
      if (!data && !data.Answer && data.Answer.length < 1) {
        throw errcode(new Error('Record not found'), 'ERR_NOT_FOUND')
      }
      const record = new Record(key, Buffer.from(data.Answer[0].data, 'base64'))
      setImmediate(() => callback(null, record.value))
github ipfs / js-ipfs / test / utils / mock-preload-node.js View on Github external
const getPreloadCids = addr => ky.get(`${toUri(addr || defaultAddr)}/cids`).json()
github ipfs / js-ipfs / src / core / ipns / routing / experimental / utils.js View on Github external
async function dohBinary (url, domain, key) {
  const start = Date.now()
  const keyStr = keyToBase32(key)
  const buf = dnsPacket.encode({
    type: 'query',
    questions: [{
      type: 'TXT',
      name: `${keyStr}.${domain}`
    }]
  })

  const result = await ky
    .get(url, {
      searchParams: {
        dns: buf.toString('base64')
      },
      headers: {
        accept: 'application/dns-message'
      }
    })
    .arrayBuffer()

  const data = dnsPacket.decode(Buffer.from(result))
  if (!data || data.answers.length < 1) {
    throw errcode(new Error('Record not found'), 'ERR_NOT_FOUND')
  }
  const record = new Record(key, Buffer.from(Buffer.concat(data.answers[0].data).toString(), 'base64'))
  console.log(`Resolved ${keyStr}.${domain} in ${(Date.now() - start)}ms`)
github ipfs / js-ipfs-http-client / src / add-from-url.js View on Github external
return async function * addFromURL (url, options) {
    options = options || {}

    const { body } = await kyDefault.get(url)

    const input = {
      path: decodeURIComponent(new URL(url).pathname.split('/').pop() || ''),
      content: toIterable(body)
    }

    yield * add(input, options)
  }
}
github ipfs / js-ipfs / src / core / ipns / routing / experimental / workers-datastore.js View on Github external
async get (key) {
    const start = Date.now()

    if (!Buffer.isBuffer(key)) {
      throw errcode(new Error(`Workers datastore key must be a buffer`), 'ERR_INVALID_KEY')
    }

    const keyStr = keyToBase32(key)

    const data = await ky
      .get('https://workers.ipns.dev', {
        searchParams: {
          key: keyStr
        }
      })
      .text()

    const record = new Record(key, Buffer.from(data, 'base64'))
    console.log(`Resolved ${keyStr} with workers in: ${(Date.now() - start)}ms`)

    return record.value
  }
}