-
Notifications
You must be signed in to change notification settings - Fork 1.2k
interface-ipfs-core for object/core #219
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
const Command = require('ronin').Command | ||
const utils = require('../../utils') | ||
const bs58 = require('bs58') | ||
const debug = require('debug') | ||
const log = debug('cli:object') | ||
log.error = debug('cli:object:error') | ||
|
@@ -21,32 +20,15 @@ module.exports = Command.extend({ | |
if (err) { | ||
throw err | ||
} | ||
if (utils.isDaemonOn()) { | ||
return ipfs.object.get(key, (err, obj) => { | ||
if (err) { | ||
log.error(err) | ||
throw err | ||
} | ||
|
||
console.log(JSON.stringify(obj)) | ||
}) | ||
} | ||
|
||
const mh = new Buffer(bs58.decode(key)) | ||
ipfs.object.get(mh, (err, obj) => { | ||
ipfs.object.get(key, {enc: 'base58'}, (err, node) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pretty sure @xicombd is going to get excited to see that now we don't need all the madness checking :) |
||
if (err) { | ||
log.error(err) | ||
throw err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will print the error twice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pattern is all over the place, should probably nuke it then everywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
} | ||
|
||
console.log(JSON.stringify({ | ||
Links: obj.links.map((link) => ({ | ||
Name: link.name, | ||
Hash: bs58.encode(link.hash).toString(), | ||
Size: link.size | ||
})), | ||
Data: obj.data.toString() | ||
})) | ||
const res = node.toJSON() | ||
res.Data = res.Data ? res.Data.toString() : '' | ||
console.log(JSON.stringify(res)) | ||
}) | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
const Command = require('ronin').Command | ||
const utils = require('../../utils') | ||
const bs58 = require('bs58') | ||
const debug = require('debug') | ||
const log = debug('cli:object') | ||
log.error = debug('cli:object:error') | ||
|
@@ -21,25 +20,15 @@ module.exports = Command.extend({ | |
if (err) { | ||
throw err | ||
} | ||
const mh = utils.isDaemonOn() | ||
? key | ||
: new Buffer(bs58.decode(key)) | ||
|
||
ipfs.object.links(mh, (err, links) => { | ||
ipfs.object.links(key, {enc: 'base58'}, (err, links) => { | ||
if (err) { | ||
log.error(err) | ||
throw err | ||
} | ||
|
||
if (links.Links) { // js-ipfs-api output | ||
links.Links.forEach((link) => { | ||
console.log(link.Hash, link.Size, link.Name) | ||
}) | ||
return | ||
} | ||
|
||
links.forEach((link) => { | ||
console.log(bs58.encode(link.hash).toString(), link.size, link.name) | ||
link = link.toJSON() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to convert it to JSON There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes there is, |
||
console.log(link.Hash, link.Size, link.Name) | ||
}) | ||
}) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet, the core api is making code simpler :D