diff --git a/.aegir.js b/.aegir.js index 43915d90d6..c09767c77d 100644 --- a/.aegir.js +++ b/.aegir.js @@ -15,7 +15,7 @@ module.exports = { }, karma: { files: [{ - pattern: 'node_modules/interface-ipfs-core/js/test/fixtures/**/*', + pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*', watched: false, served: true, included: false diff --git a/package.json b/package.json index f3bde79f98..a64d1b08c6 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "execa": "^1.0.0", "form-data": "^2.3.3", "hat": "0.0.3", - "interface-ipfs-core": "~0.96.0", + "interface-ipfs-core": "~0.97.0", "ipfsd-ctl": "~0.41.0", "libp2p-websocket-star": "~0.10.2", "ncp": "^2.0.0", diff --git a/src/core/components/resolve.js b/src/core/components/resolve.js index bd23a33b20..1ca80e8249 100644 --- a/src/core/components/resolve.js +++ b/src/core/components/resolve.js @@ -34,17 +34,16 @@ module.exports = (self) => { const path = split.slice(3).join('/') - resolve(cid, path, (err, cid) => { + resolve(cid, path, (err, res) => { if (err) return cb(err) - if (!cid) return cb(new Error('found non-link at given path')) - cb(null, `/ipfs/${cidToString(cid, { base: opts.cidBase })}`) + const { cid, remainderPath } = res + cb(null, `/ipfs/${cidToString(cid, { base: opts.cidBase })}${remainderPath ? '/' + remainderPath : ''}`) }) }) // Resolve the given CID + path to a CID. function resolve (cid, path, callback) { - let value - + let value, remainderPath doUntil( (cb) => { self.block.get(cid, (err, block) => { @@ -59,28 +58,31 @@ module.exports = (self) => { r.resolver.resolve(block.data, path, (err, result) => { if (err) return cb(err) value = result.value - path = result.remainderPath + remainderPath = result.remainderPath cb() }) }) }, () => { - const endReached = !path || path === '/' - - if (endReached) { - return true - } - - if (value) { + if (value && value['/']) { + // If we've hit a CID, replace the current CID. cid = new CID(value['/']) + path = remainderPath + } else if (CID.isCID(value)) { + // If we've hit a CID, replace the current CID. + cid = value + path = remainderPath + } else { + // We've hit a value. Return the current CID and the remaining path. + return true } - return false + // Continue resolving unless the path is empty. + return !path || path === '/' }, (err) => { if (err) return callback(err) - if (value && value['/']) return callback(null, new CID(value['/'])) - callback() + callback(null, { cid, remainderPath: path }) } ) } diff --git a/test/gateway/index.js b/test/gateway/index.js index 54e47e0ba1..0f9ac1812b 100644 --- a/test/gateway/index.js +++ b/test/gateway/index.js @@ -12,7 +12,7 @@ const path = require('path') const hat = require('hat') const fileType = require('file-type') -const bigFile = loadFixture('js/test/fixtures/15mb.random', 'interface-ipfs-core') +const bigFile = loadFixture('test/fixtures/15mb.random', 'interface-ipfs-core') const directoryContent = { 'index.html': loadFixture('test/gateway/test-folder/index.html'), 'nested-folder/hello.txt': loadFixture('test/gateway/test-folder/nested-folder/hello.txt'),