@@ -5,8 +5,7 @@ const debug = require('debug')
55const log = debug ( 'cli:object' )
66const dagPB = require ( 'ipld-dag-pb' )
77const DAGLink = dagPB . DAGLink
8- const waterfall = require ( 'async/waterfall' )
9- const parallel = require ( 'async/parallel' )
8+ const series = require ( 'async/series' )
109log . error = debug ( 'cli:object:error' )
1110
1211module . exports = {
@@ -17,29 +16,60 @@ module.exports = {
1716 builder : { } ,
1817
1918 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 ) => {
3868 if ( err ) {
3969 throw err
4070 }
4171
42- console . log ( node . Hash )
72+ console . log ( nodeB . toJSON ( ) . multihash )
4373 } )
4474 }
4575}
0 commit comments