diff --git a/packages/ipfs/src/core/components/dag/resolve.js b/packages/ipfs/src/core/components/dag/resolve.js index dd863dd111..265c0144c1 100644 --- a/packages/ipfs/src/core/components/dag/resolve.js +++ b/packages/ipfs/src/core/components/dag/resolve.js @@ -1,16 +1,36 @@ 'use strict' +const CID = require('cids') const { parseArgs } = require('./utils') const { withTimeoutOption } = require('../../utils') module.exports = ({ ipld, preload }) => { - return withTimeoutOption(async function * resolve (cid, path, options) { // eslint-disable-line require-await + return withTimeoutOption(async function resolve (cid, path, options) { [cid, path, options] = parseArgs(cid, path, options) if (options.preload !== false) { preload(cid) } - yield * ipld.resolve(cid, path, { signal: options.signal }) + let lastCid = cid + let lastRemainderPath = path + + if (path) { + for await (const { value, remainderPath } of ipld.resolve(cid, path, { + signal: options.signal + })) { + if (!CID.isCID(value)) { + break + } + + lastRemainderPath = remainderPath + lastCid = value + } + } + + return { + value: lastCid, + remainderPath: lastRemainderPath || '' + } }) }