@@ -5,8 +5,7 @@ const debug = require('debug')
5
5
const log = debug ( 'cli:object' )
6
6
const dagPB = require ( 'ipld-dag-pb' )
7
7
const DAGLink = dagPB . DAGLink
8
- const waterfall = require ( 'async/waterfall' )
9
- const parallel = require ( 'async/parallel' )
8
+ const series = require ( 'async/series' )
10
9
log . error = debug ( 'cli:object:error' )
11
10
12
11
module . exports = {
@@ -17,29 +16,60 @@ module.exports = {
17
16
builder : { } ,
18
17
19
18
handler ( argv ) {
20
- waterfall ( [
21
- ( cb ) => utils . getIPFS ( cb ) ,
22
- ( ipfs , cb ) => waterfall ( [
23
- ( cb ) => ipfs . object . get ( argv . ref , { enc : 'base58' } , cb ) ,
24
- ( linkedObj , cb ) => parallel ( [
25
- ( cb ) => linkedObj . size ( cb ) ,
26
- ( cb ) => linkedObj . multihash ( cb )
27
- ] , cb )
28
- ] , ( err , stats ) => {
29
- if ( err ) {
30
- return cb ( err )
31
- }
32
-
33
- const link = new DAGLink ( argv . name , stats [ 0 ] , stats [ 1 ] )
34
- ipfs . object . patch . addLink ( argv . root , link , { enc : 'base58' } , cb )
35
- } ) ,
36
- ( node , cb ) => node . toJSON ( cb )
37
- ] , ( err , node ) => {
19
+ let ipfs
20
+ let nodeA
21
+ let nodeB
22
+
23
+ series ( [
24
+ ( cb ) => {
25
+ utils . getIPFS ( ( err , _ipfs ) => {
26
+ if ( err ) {
27
+ return cb ( err )
28
+ }
29
+ ipfs = _ipfs
30
+ cb ( )
31
+ } )
32
+ } ,
33
+ ( cb ) => {
34
+ ipfs . object . get (
35
+ argv . ref ,
36
+ { enc : 'base58' } ,
37
+ ( err , node ) => {
38
+ console . log ( 'Do I get my node' )
39
+ if ( err ) {
40
+ return cb ( err )
41
+ }
42
+ nodeA = node
43
+ cb ( )
44
+ } )
45
+ } ,
46
+ ( cb ) => {
47
+ console . log ( 'multihash is:' , nodeA . multihash )
48
+ const link = new DAGLink (
49
+ argv . name ,
50
+ nodeA . multihash ,
51
+ nodeA . size
52
+ )
53
+
54
+ ipfs . object . patch . addLink (
55
+ argv . root ,
56
+ link ,
57
+ { enc : 'base58' } ,
58
+ ( err , node ) => {
59
+ if ( err ) {
60
+ return cb ( err )
61
+ }
62
+ nodeB = node
63
+ cb ( )
64
+ }
65
+ )
66
+ }
67
+ ] , ( err ) => {
38
68
if ( err ) {
39
69
throw err
40
70
}
41
71
42
- console . log ( node . Hash )
72
+ console . log ( nodeB . toJSON ( ) . multihash )
43
73
} )
44
74
}
45
75
}
0 commit comments