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

Commit 301dbcf

Browse files
committed
feat: migrate cli to use new async DAGNode interface
1 parent 01e56ec commit 301dbcf

File tree

7 files changed

+65
-19
lines changed

7 files changed

+65
-19
lines changed

src/cli/commands/object/get.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ module.exports = {
2323
throw err
2424
}
2525

26-
const res = node.toJSON()
27-
res.Data = res.Data ? res.Data.toString() : ''
28-
console.log(JSON.stringify(res))
26+
node.toJSON((err, nodeJSON) => {
27+
if (err) {
28+
throw err
29+
}
30+
nodeJSON.Data = nodeJSON.Data ? nodeJSON.Data.toString() : ''
31+
console.log(JSON.stringify(nodeJSON))
32+
})
2933
})
3034
})
3135
}

src/cli/commands/object/new.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ module.exports = {
2323
throw err
2424
}
2525

26-
console.log(node.toJSON().Hash)
26+
node.toJSON((err, nodeJSON) => {
27+
if (err) {
28+
throw err
29+
}
30+
console.log(nodeJSON.Hash)
31+
})
2732
})
2833
})
2934
}

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

+24-10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
const utils = require('../../../utils')
44
const debug = require('debug')
55
const log = debug('cli:object')
6-
const mDAG = require('ipfs-merkle-dag')
7-
const DAGLink = mDAG.DAGLink
6+
const dagPB = require('ipld-dag-pb')
7+
const DAGLink = dagPB.DAGLink
88
log.error = debug('cli:object:error')
99

1010
module.exports = {
@@ -21,14 +21,28 @@ module.exports = {
2121
}
2222

2323
ipfs.object.get(argv.ref, {enc: 'base58'}).then((linkedObj) => {
24-
const link = new DAGLink(
25-
argv.name,
26-
linkedObj.size(),
27-
linkedObj.multihash()
28-
)
29-
return ipfs.object.patch.addLink(argv.root, link, {enc: 'base58'})
30-
}).then((node) => {
31-
console.log(node.toJSON().Hash)
24+
linkedObj.size((err, size) => {
25+
if (err) {
26+
throw err
27+
}
28+
linkedObj.multihash((err, multihash) => {
29+
if (err) {
30+
throw err
31+
}
32+
33+
const link = new DAGLink(argv.name, size, multihash)
34+
35+
ipfs.object.patch.addLink(argv.root, link, {enc: 'base58'})
36+
.then((node) => {
37+
node.toJSON((err, nodeJSON) => {
38+
if (err) {
39+
throw err
40+
}
41+
console.log(nodeJSON.Hash)
42+
})
43+
})
44+
})
45+
})
3246
}).catch((err) => {
3347
throw err
3448
})

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ function appendData (key, data) {
1818
throw err
1919
}
2020

21-
console.log(node.toJSON().Hash)
21+
node.toJSON((err, nodeJSON) => {
22+
if (err) {
23+
throw err
24+
}
25+
26+
console.log(nodeJSON.Hash)
27+
})
2228
})
2329
})
2430
}

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const DAGLink = require('ipfs-merkle-dag').DAGLink
3+
const DAGLink = require('ipld-dag-pb').DAGLink
44
const utils = require('../../../utils')
55
const debug = require('debug')
66
const log = debug('cli:object')
@@ -26,7 +26,12 @@ module.exports = {
2626
throw err
2727
}
2828

29-
console.log(node.toJSON().Hash)
29+
node.toJSON((err, nodeJSON) => {
30+
if (err) {
31+
throw err
32+
}
33+
console.log(nodeJSON.Hash)
34+
})
3035
})
3136
})
3237
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ function parseAndAddNode (key, data) {
1818
throw err
1919
}
2020

21-
console.log(node.toJSON().Hash)
21+
node.toJSON((err, nodeJSON) => {
22+
if (err) {
23+
throw err
24+
}
25+
26+
console.log(nodeJSON.Hash)
27+
})
2228
})
2329
})
2430
}

src/cli/commands/object/put.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ function putNode (buf, enc) {
1818
throw err
1919
}
2020

21-
console.log('added', node.toJSON().Hash)
21+
node.toJSON((err, nodeJSON) => {
22+
if (err) {
23+
throw err
24+
}
25+
26+
console.log('added', nodeJSON.Hash)
27+
})
2228
})
2329
})
2430
}

0 commit comments

Comments
 (0)