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

Commit

Permalink
feat: make core/object satisfy interface-ipfs-core
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 16, 2016
1 parent c539741 commit 96013bb
Show file tree
Hide file tree
Showing 27 changed files with 388 additions and 616 deletions.
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
},
"homepage": "https://github.com/ipfs/js-ipfs#readme",
"devDependencies": {
"aegir": "^3.0.1",
"aegir": "^3.0.2",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"expose-loader": "^0.7.1",
"form-data": "^1.0.0-rc3",
"gulp": "^3.9.1",
"idb-plus-blob-store": "^1.1.2",
"interface-ipfs-core": "^0.1.5",
"libp2p-ipfs-browser": "^0.2.0",
"lodash": "^4.11.2",
"mocha": "^2.4.5",
Expand All @@ -63,24 +64,25 @@
"fs-blob-store": "^5.2.1",
"glob": "^7.0.3",
"hapi": "^13.3.0",
"ipfs-api": "^3.0.2",
"ipfs-api": "^4.0.2",
"ipfs-bitswap": "^0.2.0",
"ipfs-block": "^0.3.0",
"ipfs-block-service": "^0.4.0",
"ipfs-merkle-dag": "^0.5.1",
"ipfs-merkle-dag": "^0.6.0",
"ipfs-multipart": "^0.1.0",
"ipfs-repo": "^0.8.0",
"ipfs-unixfs-engine": "^0.6.1",
"joi": "^8.0.5",
"libp2p-ipfs": "^0.3.3",
"libp2p-ipfs": "^0.3.8",
"libp2p-swarm": "^0.12.11",
"lodash.get": "^4.2.1",
"lodash.set": "^4.1.0",
"lodash.get": "^4.3.0",
"lodash.set": "^4.2.0",
"multiaddr": "^1.4.1",
"path-exists": "^3.0.0",
"peer-book": "^0.1.1",
"peer-id": "^0.6.6",
"peer-info": "^0.6.2",
"promisify-es6": "^1.0.1",
"readable-stream": "1.1.13",
"ronin": "^0.3.11",
"run-parallel": "^1.1.6",
Expand Down
1 change: 0 additions & 1 deletion src/cli/commands/block/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = Command.extend({

ipfs.block.get(mh, (err, block) => {
if (err) {
log.error(err)
throw err
}

Expand Down
3 changes: 0 additions & 3 deletions src/cli/commands/block/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function addBlock (buf) {
if (utils.isDaemonOn()) {
return ipfs.block.put(buf, (err, block) => {
if (err) {
log.error(err)
throw err
}

Expand All @@ -31,7 +30,6 @@ function addBlock (buf) {

ipfs.block.put(block, (err, obj) => {
if (err) {
log.error(err)
throw err
}

Expand All @@ -52,7 +50,6 @@ module.exports = Command.extend({

process.stdin.pipe(bl((err, input) => {
if (err) {
log.error(err)
throw err
}

Expand Down
1 change: 0 additions & 1 deletion src/cli/commands/block/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = Command.extend({

ipfs.block.del(mh, (err) => {
if (err) {
log.error(err)
throw err
}

Expand Down
1 change: 0 additions & 1 deletion src/cli/commands/block/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = Command.extend({

ipfs.block.stat(mh, (err, block) => {
if (err) {
log.error(err)
throw err
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/bootstrap/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = Command.extend({
}
ipfs.bootstrap.add(multiaddr, (err, list) => {
if (err) {
return log.error(err)
throw err
}
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/bootstrap/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = Command.extend({
}
ipfs.bootstrap.rm(multiaddr, (err, list) => {
if (err) {
return log.error(err)
throw err
}
})
})
Expand Down
1 change: 0 additions & 1 deletion src/cli/commands/config/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ module.exports = Command.extend({

child.on('exit', (err, code) => {
if (err) {
log.error(err)
throw new Error('error on the editor')
}

Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = Command.extend({
httpAPI = new HttpAPI()
httpAPI.start((err) => {
if (err) {
return log.error(err)
throw err
}
console.log('Daemon is ready')
})
Expand All @@ -25,7 +25,7 @@ module.exports = Command.extend({
console.log('Received interrupt signal, shutting down..')
httpAPI.stop((err) => {
if (err) {
return log.error(err)
throw err
}
process.exit(0)
})
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = Command.extend({

ipfs.id((err, id) => {
if (err) {
return log.error(err)
throw err
}
console.log(id)
})
Expand Down
15 changes: 2 additions & 13 deletions src/cli/commands/object/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -21,23 +20,13 @@ module.exports = Command.extend({
if (err) {
throw err
}
const mh = utils.isDaemonOn()
? key
: new Buffer(bs58.decode(key))

ipfs.object.data(mh, (err, data) => {
ipfs.object.data(key, {enc: 'base58'}, (err, data) => {
if (err) {
log.error(err)
throw err
}

if (data instanceof Buffer) {
console.log(data.toString())
return
}

// js-ipfs-api output (http stream)
data.pipe(process.stdout)
console.log(data.toString())
})
})
}
Expand Down
26 changes: 4 additions & 22 deletions src/cli/commands/object/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) => {
if (err) {
log.error(err)
throw err
}

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))
})
})
}
Expand Down
17 changes: 3 additions & 14 deletions src/cli/commands/object/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
console.log(link.Hash, link.Size, link.Name)
})
})
})
Expand Down
14 changes: 4 additions & 10 deletions src/cli/commands/object/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -12,23 +11,18 @@ module.exports = Command.extend({

options: {},

run: (template) => {
run: () => {
utils.getIPFS((err, ipfs) => {
if (err) {
throw err
}
ipfs.object.new(template, (err, obj) => {

ipfs.object.new((err, node) => {
if (err) {
log.error(err)
throw err
}

if (typeof obj.Hash === 'string') { // js-ipfs-api output
console.log(obj.Hash)
return
}

console.log(bs58.encode(obj.Hash).toString())
console.log(node.toJSON().Hash)
})
})
}
Expand Down
42 changes: 11 additions & 31 deletions src/cli/commands/object/patch/add-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
const mDAG = require('ipfs-merkle-dag')
Expand Down Expand Up @@ -30,36 +29,17 @@ module.exports = Command.extend({
throw err
}

if (utils.isDaemonOn()) {
return ipfs.object.patch.addLink(root, name, ref, (err, obj) => {
if (err) {
log.error(err)
throw err
}

console.log(obj.Hash)
})
}

// when running locally we first need to get the ref object,
// so we can create the link with the correct size
const refMh = new Buffer(bs58.decode(ref))
ipfs.object.get(refMh, (err, linkedObj) => {
if (err) {
log.error(err)
throw err
}

const rootMh = new Buffer(bs58.decode(root))
const link = new DAGLink(name, linkedObj.size(), linkedObj.multihash())
ipfs.object.patch.addLink(rootMh, link, (err, obj) => {
if (err) {
log.error(err)
throw err
}

console.log(bs58.encode(obj.multihash()).toString())
})
ipfs.object.get(ref, {enc: 'base58'}).then((linkedObj) => {
const link = new DAGLink(
name,
linkedObj.size(),
linkedObj.multihash()
)
return ipfs.object.patch.addLink(root, link, {enc: 'base58'})
}).then((node) => {
console.log(node.toJSON().Hash)
}).catch((err) => {
throw err
})
})
}
Expand Down
Loading

0 comments on commit 96013bb

Please sign in to comment.