3
3
const promisify = require ( 'promisify-es6' )
4
4
const bl = require ( 'bl' )
5
5
const Block = require ( 'ipfs-block' )
6
+ const multihash = require ( 'multihashes' )
7
+ const CID = require ( 'cids' )
6
8
7
9
module . exports = ( send ) => {
8
10
return {
9
11
get : promisify ( ( args , opts , callback ) => {
12
+ // TODO this needs to be adjusted with the new go-ipfs http-api
13
+ if ( args && CID . isCID ( args ) ) {
14
+ args = multihash . toB58String ( args . multihash )
15
+ }
10
16
if ( typeof ( opts ) === 'function' ) {
11
17
callback = opts
12
18
opts = { }
13
19
}
20
+
14
21
return send ( {
15
22
path : 'block/get' ,
16
23
args : args ,
@@ -32,6 +39,11 @@ module.exports = (send) => {
32
39
} )
33
40
} ) ,
34
41
stat : promisify ( ( args , opts , callback ) => {
42
+ // TODO this needs to be adjusted with the new go-ipfs http-api
43
+ if ( args && CID . isCID ( args ) ) {
44
+ args = multihash . toB58String ( args . multihash )
45
+ }
46
+
35
47
if ( typeof ( opts ) === 'function' ) {
36
48
callback = opts
37
49
opts = { }
@@ -50,7 +62,13 @@ module.exports = (send) => {
50
62
} )
51
63
} )
52
64
} ) ,
53
- put : promisify ( ( block , callback ) => {
65
+ put : promisify ( ( block , cid , callback ) => {
66
+ // TODO this needs to be adjusted with the new go-ipfs http-api
67
+ if ( typeof cid === 'function' ) {
68
+ callback = cid
69
+ cid = { }
70
+ }
71
+
54
72
if ( Array . isArray ( block ) ) {
55
73
const err = new Error ( 'block.put() only accepts 1 file' )
56
74
return callback ( err )
0 commit comments