Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: resolve when value is a CID or a {'/': 'string cid'}
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
Alan Shaw committed Feb 19, 2019
1 parent d8a6c22 commit e99b7ee
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 11 additions & 6 deletions src/core/components/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ module.exports = (self) => {

const path = split.slice(3).join('/')

resolve(cid, path, (err, cid, remainder) => {
resolve(cid, path, (err, res) => {
if (err) return cb(err)
cb(null, `/ipfs/${cidToString(cid, { base: opts.cidBase })}${remainder ? '/' + remainder : ''}`)
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, remainder
let value, remainderPath
doUntil(
(cb) => {
self.block.get(cid, (err, block) => {
Expand All @@ -57,7 +58,7 @@ module.exports = (self) => {
r.resolver.resolve(block.data, path, (err, result) => {
if (err) return cb(err)
value = result.value
remainder = result.remainderPath
remainderPath = result.remainderPath
cb()
})
})
Expand All @@ -66,7 +67,11 @@ module.exports = (self) => {
if (value && value['/']) {
// If we've hit a CID, replace the current CID.
cid = new CID(value['/'])
path = remainder
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
Expand All @@ -77,7 +82,7 @@ module.exports = (self) => {
},
(err) => {
if (err) return callback(err)
callback(null, cid, path)
callback(null, { cid, remainderPath: path })
}
)
}
Expand Down
57 changes: 0 additions & 57 deletions test/core/resolve.spec.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit e99b7ee

Please sign in to comment.