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

Commit

Permalink
feat: migrate cli to use new async DAGNode interface
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Oct 29, 2016
1 parent 01e56ec commit 301dbcf
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 19 deletions.
10 changes: 7 additions & 3 deletions src/cli/commands/object/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ module.exports = {
throw err
}

const res = node.toJSON()
res.Data = res.Data ? res.Data.toString() : ''
console.log(JSON.stringify(res))
node.toJSON((err, nodeJSON) => {
if (err) {
throw err
}
nodeJSON.Data = nodeJSON.Data ? nodeJSON.Data.toString() : ''
console.log(JSON.stringify(nodeJSON))
})
})
})
}
Expand Down
7 changes: 6 additions & 1 deletion src/cli/commands/object/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ module.exports = {
throw err
}

console.log(node.toJSON().Hash)
node.toJSON((err, nodeJSON) => {
if (err) {
throw err
}
console.log(nodeJSON.Hash)
})
})
})
}
Expand Down
34 changes: 24 additions & 10 deletions src/cli/commands/object/patch/add-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const utils = require('../../../utils')
const debug = require('debug')
const log = debug('cli:object')
const mDAG = require('ipfs-merkle-dag')
const DAGLink = mDAG.DAGLink
const dagPB = require('ipld-dag-pb')
const DAGLink = dagPB.DAGLink
log.error = debug('cli:object:error')

module.exports = {
Expand All @@ -21,14 +21,28 @@ module.exports = {
}

ipfs.object.get(argv.ref, {enc: 'base58'}).then((linkedObj) => {
const link = new DAGLink(
argv.name,
linkedObj.size(),
linkedObj.multihash()
)
return ipfs.object.patch.addLink(argv.root, link, {enc: 'base58'})
}).then((node) => {
console.log(node.toJSON().Hash)
linkedObj.size((err, size) => {
if (err) {
throw err
}
linkedObj.multihash((err, multihash) => {
if (err) {
throw err
}

const link = new DAGLink(argv.name, size, multihash)

ipfs.object.patch.addLink(argv.root, link, {enc: 'base58'})
.then((node) => {
node.toJSON((err, nodeJSON) => {
if (err) {
throw err
}
console.log(nodeJSON.Hash)
})
})
})
})
}).catch((err) => {
throw err
})
Expand Down
8 changes: 7 additions & 1 deletion src/cli/commands/object/patch/append-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ function appendData (key, data) {
throw err
}

console.log(node.toJSON().Hash)
node.toJSON((err, nodeJSON) => {
if (err) {
throw err
}

console.log(nodeJSON.Hash)
})
})
})
}
Expand Down
9 changes: 7 additions & 2 deletions src/cli/commands/object/patch/rm-link.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const DAGLink = require('ipfs-merkle-dag').DAGLink
const DAGLink = require('ipld-dag-pb').DAGLink
const utils = require('../../../utils')
const debug = require('debug')
const log = debug('cli:object')
Expand All @@ -26,7 +26,12 @@ module.exports = {
throw err
}

console.log(node.toJSON().Hash)
node.toJSON((err, nodeJSON) => {
if (err) {
throw err
}
console.log(nodeJSON.Hash)
})
})
})
}
Expand Down
8 changes: 7 additions & 1 deletion src/cli/commands/object/patch/set-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ function parseAndAddNode (key, data) {
throw err
}

console.log(node.toJSON().Hash)
node.toJSON((err, nodeJSON) => {
if (err) {
throw err
}

console.log(nodeJSON.Hash)
})
})
})
}
Expand Down
8 changes: 7 additions & 1 deletion src/cli/commands/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ function putNode (buf, enc) {
throw err
}

console.log('added', node.toJSON().Hash)
node.toJSON((err, nodeJSON) => {
if (err) {
throw err
}

console.log('added', nodeJSON.Hash)
})
})
})
}
Expand Down

0 comments on commit 301dbcf

Please sign in to comment.