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' )
6
7
7
8
module . exports = ( send ) => {
8
9
return {
9
10
get : promisify ( ( args , opts , callback ) => {
11
+ // TODO this needs to be adjusted with the new go-ipfs
12
+ // http-api
13
+ if ( args . constructor && args . constructor . name === 'CID' ) {
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,12 @@ 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
43
+ // http-api
44
+ if ( opts . constructor && opts . constructor . name === 'CID' ) {
45
+ opts = { }
46
+ }
47
+
35
48
if ( typeof ( opts ) === 'function' ) {
36
49
callback = opts
37
50
opts = { }
@@ -50,7 +63,15 @@ module.exports = (send) => {
50
63
} )
51
64
} )
52
65
} ) ,
53
- put : promisify ( ( block , callback ) => {
66
+ put : promisify ( ( block , cid , callback ) => {
67
+ // TODO this needs to be adjusted with the new go-ipfs
68
+ // http-api
69
+
70
+ if ( typeof ( cid ) === 'function' ) {
71
+ callback = cid
72
+ cid = { }
73
+ }
74
+
54
75
if ( Array . isArray ( block ) ) {
55
76
const err = new Error ( 'block.put() only accepts 1 file' )
56
77
return callback ( err )
0 commit comments