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

Commit 8e58225

Browse files
pgtedaviddias
authored andcommitted
fix: adapting HTTP API to the interface-ipfs-core spec (#625)
* adating HTTP API to the interface-ipfs-core spec * chore: update deps
1 parent 797be79 commit 8e58225

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"readable-stream": "^2.3.3",
5050
"stream-http": "^2.7.2",
5151
"streamifier": "^0.1.1",
52-
"tar-stream": "^1.5.4"
52+
"tar-stream": "^1.5.5"
5353
},
5454
"engines": {
5555
"node": ">=6.0.0",
@@ -65,7 +65,7 @@
6565
"dirty-chai": "^2.0.1",
6666
"eslint-plugin-react": "^7.4.0",
6767
"gulp": "^3.9.1",
68-
"interface-ipfs-core": "~0.34.0",
68+
"interface-ipfs-core": "~0.34.3",
6969
"hapi": "^16.6.2",
7070
"ipfsd-ctl": "~0.24.1",
7171
"pre-commit": "^1.2.2",

src/ls.js

+43-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,48 @@ module.exports = (arg) => {
1515
path: 'ls',
1616
args: args,
1717
qs: opts
18-
}, callback)
18+
}, (err, results) => {
19+
if (err) {
20+
return callback(err)
21+
}
22+
23+
let result = results.Objects
24+
if (!result) {
25+
return callback(new Error('expected .Objects in results'))
26+
}
27+
28+
result = result[0]
29+
if (!result) {
30+
return callback(new Error('expected one array in results.Objects'))
31+
}
32+
33+
result = result.Links
34+
if (!Array.isArray(result)) {
35+
return callback(new Error('expected one array in results.Objects[0].Links'))
36+
}
37+
38+
result = result.map((link) => ({
39+
depth: 1,
40+
name: link.Name,
41+
path: args + '/' + link.Name,
42+
size: link.Size,
43+
hash: link.Hash,
44+
type: typeOf(link)
45+
}))
46+
47+
callback(null, result)
48+
})
1949
})
2050
}
51+
52+
function typeOf (link) {
53+
switch (link.Type) {
54+
case 1:
55+
case 5:
56+
return 'dir'
57+
case 2:
58+
return 'file'
59+
default:
60+
return 'unknown'
61+
}
62+
}

test/ls.spec.js

-20
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,6 @@ describe('.ls', function () {
4040
after((done) => fc.dismantle(done))
4141

4242
describe('Callback API', () => {
43-
it('should correctly retrieve links', function (done) {
44-
ipfs.ls(folder, (err, res) => {
45-
expect(err).to.not.exist()
46-
47-
expect(res).to.have.a.property('Objects')
48-
expect(res.Objects[0]).to.have.a.property('Links')
49-
expect(res.Objects[0]).to.have.property('Hash', 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh')
50-
done()
51-
})
52-
})
53-
5443
it('should correctly handle a nonexist()ing hash', function (done) {
5544
ipfs.ls('surelynotavalidhashheh?', (err, res) => {
5645
expect(err).to.exist()
@@ -69,15 +58,6 @@ describe('.ls', function () {
6958
})
7059

7160
describe('Promises API', () => {
72-
it('should correctly retrieve links', () => {
73-
return ipfs.ls(folder)
74-
.then((res) => {
75-
expect(res).to.have.a.property('Objects')
76-
expect(res.Objects[0]).to.have.a.property('Links')
77-
expect(res.Objects[0]).to.have.property('Hash', 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh')
78-
})
79-
})
80-
8161
it('should correctly handle a nonexist()ing hash', () => {
8262
return ipfs.ls('surelynotavalidhashheh?')
8363
.catch((err) => expect(err).to.exist())

0 commit comments

Comments
 (0)