src/http/api/resources/dag.js
// main route handler which is called after the above `parseArgs`, but only if the args were valid
main route handler which is called after the above `parseArgs`, but only if the args were valid
main route handler which is called after the above ` parseArgs ` but only if the args were valid
async handler (request, h) {
    let { ref, path } = request.pre.args
    const { ipfs } = request.server.app
    try {
      let lastCid = ref
      let lastRemainderPath = path
      while (true) {
        const block = await ipfs.block.get(lastCid)
        const codec = ipfs._ipld.resolvers[lastCid.codec]
        if (!codec) {
          throw Boom.badRequest(`Missing IPLD format "${lastCid.codec}"`)
        }
        const resolve = promisify(codec.resolver.resolve)
        const res = await resolve(block.data, lastRemainderPath)
        if (!res.remainderPath) {
          break
        }
        lastRemainderPath = res.remainderPath
        if (!CID.isCID(res.value)) {
          break
        }
        lastCid = res.value
      }
      return h.response({
        Cid: {
          '/': cidToString(lastCid, {
            base: request.query['cid-base']
          })
        },
        RemPath: lastRemainderPath || ''
      })
    } catch (err) {
      throw Boom.boomify(err)
    }
  }
async handler ( request , h ) { let { ref , path } = request . pre . args const { ipfs } = request . server . app try { let lastCid = ref let lastRemainderPath = path while ( true ) { const block = await ipfs . block . get ( lastCid ) const codec = ipfs . _ipld . resolvers [ lastCid . codec ] if ( ! codec ) { throw Boom . badRequest ( ` ${ lastCid . codec } ` ) } const resolve = promisify ( codec . resolver . resolve ) const res = await resolve ( block . data , lastRemainderPath ) if ( ! res . remainderPath ) { break } lastRemainderPath = res . remainderPath if ( ! CID . isCID ( res . value ) ) { break } lastCid = res . value } return h . response ( { Cid : { '/' : cidToString ( lastCid , { base : request . query [ 'cid-base' ] } ) } , RemPath : lastRemainderPath || '' } ) } catch ( err ) { throw Boom . boomify ( err ) } }
main route handler which is called after the above `parseArgs`, but only if the args were valid
main route handler which is called after the above ` parseArgs ` but only if the args were valid
// to be consistent with go we need to return the CID to the last node we've traversed // along with the path inside that node as the remainder path