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

Commit 96013bb

Browse files
feat: make core/object satisfy interface-ipfs-core
1 parent c539741 commit 96013bb

File tree

27 files changed

+388
-616
lines changed

27 files changed

+388
-616
lines changed

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737
},
3838
"homepage": "https://github.com./ipfs/js-ipfs#readme",
3939
"devDependencies": {
40-
"aegir": "^3.0.1",
40+
"aegir": "^3.0.2",
4141
"buffer-loader": "0.0.1",
4242
"chai": "^3.5.0",
4343
"expose-loader": "^0.7.1",
4444
"form-data": "^1.0.0-rc3",
4545
"gulp": "^3.9.1",
4646
"idb-plus-blob-store": "^1.1.2",
47+
"interface-ipfs-core": "^0.1.5",
4748
"libp2p-ipfs-browser": "^0.2.0",
4849
"lodash": "^4.11.2",
4950
"mocha": "^2.4.5",
@@ -63,24 +64,25 @@
6364
"fs-blob-store": "^5.2.1",
6465
"glob": "^7.0.3",
6566
"hapi": "^13.3.0",
66-
"ipfs-api": "^3.0.2",
67+
"ipfs-api": "^4.0.2",
6768
"ipfs-bitswap": "^0.2.0",
6869
"ipfs-block": "^0.3.0",
6970
"ipfs-block-service": "^0.4.0",
70-
"ipfs-merkle-dag": "^0.5.1",
71+
"ipfs-merkle-dag": "^0.6.0",
7172
"ipfs-multipart": "^0.1.0",
7273
"ipfs-repo": "^0.8.0",
7374
"ipfs-unixfs-engine": "^0.6.1",
7475
"joi": "^8.0.5",
75-
"libp2p-ipfs": "^0.3.3",
76+
"libp2p-ipfs": "^0.3.8",
7677
"libp2p-swarm": "^0.12.11",
77-
"lodash.get": "^4.2.1",
78-
"lodash.set": "^4.1.0",
78+
"lodash.get": "^4.3.0",
79+
"lodash.set": "^4.2.0",
7980
"multiaddr": "^1.4.1",
8081
"path-exists": "^3.0.0",
8182
"peer-book": "^0.1.1",
8283
"peer-id": "^0.6.6",
8384
"peer-info": "^0.6.2",
85+
"promisify-es6": "^1.0.1",
8486
"readable-stream": "1.1.13",
8587
"ronin": "^0.3.11",
8688
"run-parallel": "^1.1.6",

src/cli/commands/block/get.js

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module.exports = Command.extend({
2828

2929
ipfs.block.get(mh, (err, block) => {
3030
if (err) {
31-
log.error(err)
3231
throw err
3332
}
3433

src/cli/commands/block/put.js

-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function addBlock (buf) {
1919
if (utils.isDaemonOn()) {
2020
return ipfs.block.put(buf, (err, block) => {
2121
if (err) {
22-
log.error(err)
2322
throw err
2423
}
2524

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

3231
ipfs.block.put(block, (err, obj) => {
3332
if (err) {
34-
log.error(err)
3533
throw err
3634
}
3735

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

5351
process.stdin.pipe(bl((err, input) => {
5452
if (err) {
55-
log.error(err)
5653
throw err
5754
}
5855

src/cli/commands/block/rm.js

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ module.exports = Command.extend({
3131

3232
ipfs.block.del(mh, (err) => {
3333
if (err) {
34-
log.error(err)
3534
throw err
3635
}
3736

src/cli/commands/block/stat.js

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module.exports = Command.extend({
2828

2929
ipfs.block.stat(mh, (err, block) => {
3030
if (err) {
31-
log.error(err)
3231
throw err
3332
}
3433

src/cli/commands/bootstrap/add.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = Command.extend({
1818
}
1919
ipfs.bootstrap.add(multiaddr, (err, list) => {
2020
if (err) {
21-
return log.error(err)
21+
throw err
2222
}
2323
})
2424
})

src/cli/commands/bootstrap/rm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = Command.extend({
1818
}
1919
ipfs.bootstrap.rm(multiaddr, (err, list) => {
2020
if (err) {
21-
return log.error(err)
21+
throw err
2222
}
2323
})
2424
})

src/cli/commands/config/edit.js

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ module.exports = Command.extend({
6161

6262
child.on('exit', (err, code) => {
6363
if (err) {
64-
log.error(err)
6564
throw new Error('error on the editor')
6665
}
6766

src/cli/commands/daemon.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = Command.extend({
1616
httpAPI = new HttpAPI()
1717
httpAPI.start((err) => {
1818
if (err) {
19-
return log.error(err)
19+
throw err
2020
}
2121
console.log('Daemon is ready')
2222
})
@@ -25,7 +25,7 @@ module.exports = Command.extend({
2525
console.log('Received interrupt signal, shutting down..')
2626
httpAPI.stop((err) => {
2727
if (err) {
28-
return log.error(err)
28+
throw err
2929
}
3030
process.exit(0)
3131
})

src/cli/commands/id.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = Command.extend({
2424

2525
ipfs.id((err, id) => {
2626
if (err) {
27-
return log.error(err)
27+
throw err
2828
}
2929
console.log(id)
3030
})

src/cli/commands/object/data.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const Command = require('ronin').Command
44
const utils = require('../../utils')
5-
const bs58 = require('bs58')
65
const debug = require('debug')
76
const log = debug('cli:object')
87
log.error = debug('cli:object:error')
@@ -21,23 +20,13 @@ module.exports = Command.extend({
2120
if (err) {
2221
throw err
2322
}
24-
const mh = utils.isDaemonOn()
25-
? key
26-
: new Buffer(bs58.decode(key))
2723

28-
ipfs.object.data(mh, (err, data) => {
24+
ipfs.object.data(key, {enc: 'base58'}, (err, data) => {
2925
if (err) {
30-
log.error(err)
3126
throw err
3227
}
3328

34-
if (data instanceof Buffer) {
35-
console.log(data.toString())
36-
return
37-
}
38-
39-
// js-ipfs-api output (http stream)
40-
data.pipe(process.stdout)
29+
console.log(data.toString())
4130
})
4231
})
4332
}

src/cli/commands/object/get.js

+4-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const Command = require('ronin').Command
44
const utils = require('../../utils')
5-
const bs58 = require('bs58')
65
const debug = require('debug')
76
const log = debug('cli:object')
87
log.error = debug('cli:object:error')
@@ -21,32 +20,15 @@ module.exports = Command.extend({
2120
if (err) {
2221
throw err
2322
}
24-
if (utils.isDaemonOn()) {
25-
return ipfs.object.get(key, (err, obj) => {
26-
if (err) {
27-
log.error(err)
28-
throw err
29-
}
3023

31-
console.log(JSON.stringify(obj))
32-
})
33-
}
34-
35-
const mh = new Buffer(bs58.decode(key))
36-
ipfs.object.get(mh, (err, obj) => {
24+
ipfs.object.get(key, {enc: 'base58'}, (err, node) => {
3725
if (err) {
38-
log.error(err)
3926
throw err
4027
}
4128

42-
console.log(JSON.stringify({
43-
Links: obj.links.map((link) => ({
44-
Name: link.name,
45-
Hash: bs58.encode(link.hash).toString(),
46-
Size: link.size
47-
})),
48-
Data: obj.data.toString()
49-
}))
29+
const res = node.toJSON()
30+
res.Data = res.Data ? res.Data.toString() : ''
31+
console.log(JSON.stringify(res))
5032
})
5133
})
5234
}

src/cli/commands/object/links.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const Command = require('ronin').Command
44
const utils = require('../../utils')
5-
const bs58 = require('bs58')
65
const debug = require('debug')
76
const log = debug('cli:object')
87
log.error = debug('cli:object:error')
@@ -21,25 +20,15 @@ module.exports = Command.extend({
2120
if (err) {
2221
throw err
2322
}
24-
const mh = utils.isDaemonOn()
25-
? key
26-
: new Buffer(bs58.decode(key))
2723

28-
ipfs.object.links(mh, (err, links) => {
24+
ipfs.object.links(key, {enc: 'base58'}, (err, links) => {
2925
if (err) {
30-
log.error(err)
3126
throw err
3227
}
3328

34-
if (links.Links) { // js-ipfs-api output
35-
links.Links.forEach((link) => {
36-
console.log(link.Hash, link.Size, link.Name)
37-
})
38-
return
39-
}
40-
4129
links.forEach((link) => {
42-
console.log(bs58.encode(link.hash).toString(), link.size, link.name)
30+
link = link.toJSON()
31+
console.log(link.Hash, link.Size, link.Name)
4332
})
4433
})
4534
})

src/cli/commands/object/new.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const Command = require('ronin').Command
44
const utils = require('../../utils')
5-
const bs58 = require('bs58')
65
const debug = require('debug')
76
const log = debug('cli:object')
87
log.error = debug('cli:object:error')
@@ -12,23 +11,18 @@ module.exports = Command.extend({
1211

1312
options: {},
1413

15-
run: (template) => {
14+
run: () => {
1615
utils.getIPFS((err, ipfs) => {
1716
if (err) {
1817
throw err
1918
}
20-
ipfs.object.new(template, (err, obj) => {
19+
20+
ipfs.object.new((err, node) => {
2121
if (err) {
22-
log.error(err)
2322
throw err
2423
}
2524

26-
if (typeof obj.Hash === 'string') { // js-ipfs-api output
27-
console.log(obj.Hash)
28-
return
29-
}
30-
31-
console.log(bs58.encode(obj.Hash).toString())
25+
console.log(node.toJSON().Hash)
3226
})
3327
})
3428
}

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

+11-31
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const Command = require('ronin').Command
44
const utils = require('../../../utils')
5-
const bs58 = require('bs58')
65
const debug = require('debug')
76
const log = debug('cli:object')
87
const mDAG = require('ipfs-merkle-dag')
@@ -30,36 +29,17 @@ module.exports = Command.extend({
3029
throw err
3130
}
3231

33-
if (utils.isDaemonOn()) {
34-
return ipfs.object.patch.addLink(root, name, ref, (err, obj) => {
35-
if (err) {
36-
log.error(err)
37-
throw err
38-
}
39-
40-
console.log(obj.Hash)
41-
})
42-
}
43-
44-
// when running locally we first need to get the ref object,
45-
// so we can create the link with the correct size
46-
const refMh = new Buffer(bs58.decode(ref))
47-
ipfs.object.get(refMh, (err, linkedObj) => {
48-
if (err) {
49-
log.error(err)
50-
throw err
51-
}
52-
53-
const rootMh = new Buffer(bs58.decode(root))
54-
const link = new DAGLink(name, linkedObj.size(), linkedObj.multihash())
55-
ipfs.object.patch.addLink(rootMh, link, (err, obj) => {
56-
if (err) {
57-
log.error(err)
58-
throw err
59-
}
60-
61-
console.log(bs58.encode(obj.multihash()).toString())
62-
})
32+
ipfs.object.get(ref, {enc: 'base58'}).then((linkedObj) => {
33+
const link = new DAGLink(
34+
name,
35+
linkedObj.size(),
36+
linkedObj.multihash()
37+
)
38+
return ipfs.object.patch.addLink(root, link, {enc: 'base58'})
39+
}).then((node) => {
40+
console.log(node.toJSON().Hash)
41+
}).catch((err) => {
42+
throw err
6343
})
6444
})
6545
}

0 commit comments

Comments
 (0)