Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: adapting HTTP API to the interface-ipfs-core spec (#625)
Browse files Browse the repository at this point in the history
* adating HTTP API to the interface-ipfs-core spec

* chore: update deps
  • Loading branch information
pgte authored and daviddias committed Nov 14, 2017
1 parent 797be79 commit 8e58225
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"readable-stream": "^2.3.3",
"stream-http": "^2.7.2",
"streamifier": "^0.1.1",
"tar-stream": "^1.5.4"
"tar-stream": "^1.5.5"
},
"engines": {
"node": ">=6.0.0",
Expand All @@ -65,7 +65,7 @@
"dirty-chai": "^2.0.1",
"eslint-plugin-react": "^7.4.0",
"gulp": "^3.9.1",
"interface-ipfs-core": "~0.34.0",
"interface-ipfs-core": "~0.34.3",
"hapi": "^16.6.2",
"ipfsd-ctl": "~0.24.1",
"pre-commit": "^1.2.2",
Expand Down
44 changes: 43 additions & 1 deletion src/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,48 @@ module.exports = (arg) => {
path: 'ls',
args: args,
qs: opts
}, callback)
}, (err, results) => {
if (err) {
return callback(err)
}

let result = results.Objects
if (!result) {
return callback(new Error('expected .Objects in results'))
}

result = result[0]
if (!result) {
return callback(new Error('expected one array in results.Objects'))
}

result = result.Links
if (!Array.isArray(result)) {
return callback(new Error('expected one array in results.Objects[0].Links'))
}

result = result.map((link) => ({
depth: 1,
name: link.Name,
path: args + '/' + link.Name,
size: link.Size,
hash: link.Hash,
type: typeOf(link)
}))

callback(null, result)
})
})
}

function typeOf (link) {
switch (link.Type) {
case 1:
case 5:
return 'dir'
case 2:
return 'file'
default:
return 'unknown'
}
}
20 changes: 0 additions & 20 deletions test/ls.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ describe('.ls', function () {
after((done) => fc.dismantle(done))

describe('Callback API', () => {
it('should correctly retrieve links', function (done) {
ipfs.ls(folder, (err, res) => {
expect(err).to.not.exist()

expect(res).to.have.a.property('Objects')
expect(res.Objects[0]).to.have.a.property('Links')
expect(res.Objects[0]).to.have.property('Hash', 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh')
done()
})
})

it('should correctly handle a nonexist()ing hash', function (done) {
ipfs.ls('surelynotavalidhashheh?', (err, res) => {
expect(err).to.exist()
Expand All @@ -69,15 +58,6 @@ describe('.ls', function () {
})

describe('Promises API', () => {
it('should correctly retrieve links', () => {
return ipfs.ls(folder)
.then((res) => {
expect(res).to.have.a.property('Objects')
expect(res.Objects[0]).to.have.a.property('Links')
expect(res.Objects[0]).to.have.property('Hash', 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh')
})
})

it('should correctly handle a nonexist()ing hash', () => {
return ipfs.ls('surelynotavalidhashheh?')
.catch((err) => expect(err).to.exist())
Expand Down

0 comments on commit 8e58225

Please sign in to comment.