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

Commit 3bb3ba8

Browse files
committed
feat(cli): migrate to awesome-dag-pb
1 parent ca9935f commit 3bb3ba8

File tree

11 files changed

+103
-52
lines changed

11 files changed

+103
-52
lines changed

src/cli/commands/object/get.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,32 @@ module.exports = {
1616
handler (argv) {
1717
waterfall([
1818
(cb) => utils.getIPFS(cb),
19-
(ipfs, cb) => ipfs.object.get(argv.key, {enc: 'base58'}, cb),
20-
(node, cb) => node.toJSON(cb)
21-
], (err, nodeJson) => {
19+
(ipfs, cb) => ipfs.object.get(
20+
argv.key,
21+
{ enc: 'base58' },
22+
cb)
23+
], (err, node) => {
2224
if (err) {
2325
throw err
2426
}
27+
const nodeJSON = node.toJSON()
2528

26-
nodeJson.Data = nodeJson.Data ? nodeJson.Data.toString() : ''
27-
console.log(JSON.stringify(nodeJson))
29+
nodeJSON.data = nodeJSON.data ? nodeJSON.data.toString() : ''
30+
31+
const answer = {
32+
Data: nodeJSON.data,
33+
Hash: nodeJSON.multihash,
34+
Size: nodeJSON.size,
35+
Links: nodeJSON.links.map((l) => {
36+
return {
37+
Name: l.name,
38+
Size: l.size,
39+
Hash: l.multihash
40+
}
41+
})
42+
}
43+
44+
console.log(JSON.stringify(answer))
2845
})
2946
}
3047
}

src/cli/commands/object/links.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ module.exports = {
2525

2626
links.forEach((link) => {
2727
link = link.toJSON()
28-
console.log(link.Hash, link.Size, link.Name)
28+
29+
console.log(
30+
link.multihash,
31+
link.size,
32+
link.name
33+
)
2934
})
3035
})
3136
})

src/cli/commands/object/new.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ module.exports = {
1616
handler (argv) {
1717
waterfall([
1818
(cb) => utils.getIPFS(cb),
19-
(ipfs, cb) => ipfs.object.new(cb),
20-
(node, cb) => node.toJSON(cb)
19+
(ipfs, cb) => ipfs.object.new(cb)
2120
], (err, node) => {
2221
if (err) {
2322
throw err
2423
}
2524

26-
console.log(node.Hash)
25+
const nodeJSON = node.toJSON()
26+
27+
console.log(nodeJSON.multihash)
2728
})
2829
}
2930
}

src/cli/commands/object/patch/add-link.js

+51-21
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const debug = require('debug')
55
const log = debug('cli:object')
66
const dagPB = require('ipld-dag-pb')
77
const DAGLink = dagPB.DAGLink
8-
const waterfall = require('async/waterfall')
9-
const parallel = require('async/parallel')
8+
const series = require('async/series')
109
log.error = debug('cli:object:error')
1110

1211
module.exports = {
@@ -17,29 +16,60 @@ module.exports = {
1716
builder: {},
1817

1918
handler (argv) {
20-
waterfall([
21-
(cb) => utils.getIPFS(cb),
22-
(ipfs, cb) => waterfall([
23-
(cb) => ipfs.object.get(argv.ref, {enc: 'base58'}, cb),
24-
(linkedObj, cb) => parallel([
25-
(cb) => linkedObj.size(cb),
26-
(cb) => linkedObj.multihash(cb)
27-
], cb)
28-
], (err, stats) => {
29-
if (err) {
30-
return cb(err)
31-
}
32-
33-
const link = new DAGLink(argv.name, stats[0], stats[1])
34-
ipfs.object.patch.addLink(argv.root, link, {enc: 'base58'}, cb)
35-
}),
36-
(node, cb) => node.toJSON(cb)
37-
], (err, node) => {
19+
let ipfs
20+
let nodeA
21+
let nodeB
22+
23+
series([
24+
(cb) => {
25+
utils.getIPFS((err, _ipfs) => {
26+
if (err) {
27+
return cb(err)
28+
}
29+
ipfs = _ipfs
30+
cb()
31+
})
32+
},
33+
(cb) => {
34+
ipfs.object.get(
35+
argv.ref,
36+
{ enc: 'base58' },
37+
(err, node) => {
38+
console.log('Do I get my node')
39+
if (err) {
40+
return cb(err)
41+
}
42+
nodeA = node
43+
cb()
44+
})
45+
},
46+
(cb) => {
47+
console.log('multihash is:', nodeA.multihash)
48+
const link = new DAGLink(
49+
argv.name,
50+
nodeA.multihash,
51+
nodeA.size
52+
)
53+
54+
ipfs.object.patch.addLink(
55+
argv.root,
56+
link,
57+
{ enc: 'base58' },
58+
(err, node) => {
59+
if (err) {
60+
return cb(err)
61+
}
62+
nodeB = node
63+
cb()
64+
}
65+
)
66+
}
67+
], (err) => {
3868
if (err) {
3969
throw err
4070
}
4171

42-
console.log(node.Hash)
72+
console.log(nodeB.toJSON().multihash)
4373
})
4474
}
4575
}

src/cli/commands/object/patch/append-data.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ log.error = debug('cli:object:error')
1111
function appendData (key, data) {
1212
waterfall([
1313
(cb) => utils.getIPFS(cb),
14-
(ipfs, cb) => ipfs.object.patch.appendData(key, data, {enc: 'base58'}, cb),
15-
(node, cb) => node.toJSON(cb)
14+
(ipfs, cb) => ipfs.object.patch.appendData(key, data, {enc: 'base58'}, cb)
1615
], (err, node) => {
1716
if (err) {
1817
throw err
1918
}
19+
const nodeJSON = node.toJSON()
2020

21-
console.log(node.Hash)
21+
console.log(nodeJSON.multihash)
2222
})
2323
}
2424

src/cli/commands/object/patch/rm-link.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ module.exports = {
1919

2020
waterfall([
2121
(cb) => utils.getIPFS(cb),
22-
(ipfs, cb) => ipfs.object.patch.rmLink(argv.root, dLink, {enc: 'base58'}, cb),
23-
(node, cb) => node.toJSON(cb)
22+
(ipfs, cb) => ipfs.object.patch.rmLink(argv.root, dLink, {enc: 'base58'}, cb)
2423
], (err, node) => {
2524
if (err) {
2625
throw err
2726
}
2827

29-
console.log(node.Hash)
28+
const nodeJSON = node.toJSON()
29+
30+
console.log(nodeJSON.multihash)
3031
})
3132
}
3233
}

src/cli/commands/object/patch/set-data.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ log.error = debug('cli:object:error')
1111
function parseAndAddNode (key, data) {
1212
waterfall([
1313
(cb) => utils.getIPFS(cb),
14-
(ipfs, cb) => ipfs.object.patch.setData(key, data, {enc: 'base58'}, cb),
15-
(node, cb) => node.toJSON(cb)
14+
(ipfs, cb) => ipfs.object.patch.setData(key, data, {enc: 'base58'}, cb)
1615
], (err, node) => {
1716
if (err) {
1817
throw err
1918
}
19+
const nodeJSON = node.toJSON()
2020

21-
console.log(node.Hash)
21+
console.log(nodeJSON.multihash)
2222
})
2323
}
2424

src/cli/commands/object/put.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ log.error = debug('cli:object:error')
1111
function putNode (buf, enc) {
1212
waterfall([
1313
(cb) => utils.getIPFS(cb),
14-
(ipfs, cb) => ipfs.object.put(buf, {enc: enc}, cb),
15-
(node, cb) => node.toJSON(cb)
14+
(ipfs, cb) => ipfs.object.put(buf, {enc: enc}, cb)
1615
], (err, node) => {
1716
if (err) {
1817
throw err
1918
}
2019

21-
console.log('added', node.Hash)
20+
const nodeJSON = node.toJSON()
21+
22+
console.log('added', nodeJSON.multihash)
2223
})
2324
}
2425

@@ -36,7 +37,9 @@ module.exports = {
3637

3738
handler (argv) {
3839
if (argv.data) {
39-
return putNode(fs.readFileSync(argv.data), argv.inputenc)
40+
const buf = fs.readFileSync(argv.data)
41+
putNode(buf, argv.inputenc)
42+
return
4043
}
4144

4245
process.stdin.pipe(bl((err, input) => {

src/cli/commands/swarm/peers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ module.exports = {
2222
throw new Error('This command must be run in online mode. Try running \'ipfs daemon\' first.')
2323
}
2424

25-
ipfs.swarm.peers((err, res) => {
25+
ipfs.swarm.peers((err, result) => {
2626
if (err) {
2727
throw err
2828
}
2929

30-
res.forEach((addr) => {
31-
console.log(addr.toString())
30+
result.forEach((item) => {
31+
console.log(item.addr.toString())
3232
})
3333
})
3434
})

src/http-api/resources/object.js

-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ exports.put = {
188188
const ipfs = request.server.app.ipfs
189189
let node = request.pre.args.node
190190

191-
console.log('HANDLER')
192-
193191
series([
194192
(cb) => {
195193
DAGNode.create(new Buffer(node.Data), node.Links, (err, _node) => {

test/core/both/test-bitswap.js

-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ describe('bitswap', () => {
103103
const remoteNode = new API(apiUrl)
104104

105105
connectNodes(remoteNode, inProcNode, (err) => {
106-
console.log('connected')
107106
done(err, remoteNode)
108107
})
109108
}
@@ -207,22 +206,19 @@ describe('bitswap', () => {
207206

208207
it('2 peers', (done) => {
209208
const file = new Buffer(`I love IPFS <3 ${Math.random()}`)
210-
console.log('1')
211209

212210
waterfall([
213211
// 0. Start node
214212
(cb) => addNode(12, cb),
215213
// 1. Add file to tmp instance
216214
(remote, cb) => {
217-
console.log('2')
218215
remote.files.add([{
219216
path: 'awesome.txt',
220217
content: file
221218
}], cb)
222219
},
223220
// 2. Request file from local instance
224221
(val, cb) => {
225-
console.log('3')
226222
inProcNode.files.cat(val[0].hash, cb)
227223
},
228224
(res, cb) => res.pipe(bl(cb))

0 commit comments

Comments
 (0)