How to use the ky-universal.default.put 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
put (key, value, callback) {
    if (!Buffer.isBuffer(key)) {
      return callback(errcode(new Error('DNS datastore key must be a buffer'), 'ERR_INVALID_KEY'))
    }

    if (!Buffer.isBuffer(value)) {
      return callback(errcode(new Error(`DNS datastore value must be a buffer`), 'ERR_INVALID_VALUE'))
    }

    const cid = new Cid(key.slice(ipns.namespaceLength))

    // http://localhost:8000
    // https://ipns.dev
    ky.put(
      'https://ipns.dev',
      {
        json: {
          key: cid.toV1().toString(),
          record: value.toString('base64')
        }
      })
      .then(data => {
        setImmediate(() => callback())
      })
      .catch(err => {
        setImmediate(() => callback(err))
      })
  }
github ipfs / js-ipfs / src / core / ipns / routing / experimental / workers-datastore.js View on Github external
async put (key, value) {
    const start = Date.now()
    if (key.toString().startsWith('/pk/')) {
      return
    }
    if (!Buffer.isBuffer(key)) {
      throw errcode(new Error('Workers datastore key must be a buffer'), 'ERR_INVALID_KEY')
    }
    if (!Buffer.isBuffer(value)) {
      throw errcode(new Error(`Workers datastore value must be a buffer`), 'ERR_INVALID_VALUE')
    }

    const keyStr = keyToBase32(key)
    await ky.put(
      'https://workers.ipns.dev',
      {
        json: {
          key: keyStr,
          value: value.toString('base64')
        }
      })

    console.log(`
    Workers Store
    Domain: workers.ipns.dev
    Key: ${keyStr}
    Time: ${(Date.now() - start)}ms
    `)
  }
github ipfs / js-ipfs / src / core / ipns / routing / experimental / mdns-datastore.js View on Github external
async put (key, value) {
    const start = Date.now()
    if (key.toString().startsWith('/pk/')) {
      return
    }
    if (!Buffer.isBuffer(key)) {
      throw errcode(new Error('MDNS datastore key must be a buffer'), 'ERR_INVALID_KEY')
    }
    if (!Buffer.isBuffer(value)) {
      throw errcode(new Error(`MDNS datastore value must be a buffer`), 'ERR_INVALID_VALUE')
    }

    const keyStr = keyToBase32(key)
    await ky.put(
      'http://ipns.local:8000',
      {
        json: {
          key: keyStr,
          record: value.toString('base64')
        }
      })
    console.log(`
    Local Store
    Domain: ipns.local
    Key: ${keyStr}
    Time: ${(Date.now() - start)}ms
    `)
  }