This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +74
-23
lines changed Expand file tree Collapse file tree 7 files changed +74
-23
lines changed Original file line number Diff line number Diff line change 76
76
"ipfs-api" : " ^2.13.1" ,
77
77
"ipfs-blocks" : " ^0.1.0" ,
78
78
"ipfs-merkle-dag" : " ^0.2.1" ,
79
- "ipfs-multipart" : " 0.0.1 " ,
79
+ "ipfs-multipart" : " ^0.1.0 " ,
80
80
"ipfs-repo" : " ^0.5.0" ,
81
81
"joi" : " ^8.0.2" ,
82
82
"lodash.get" : " ^4.0.0" ,
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const Command = require ( 'ronin' ) . Command
4
- const IPFS = require ( '../../../ipfs-core ' )
4
+ const utils = require ( '../../utils ' )
5
5
const bs58 = require ( 'bs58' )
6
6
const debug = require ( 'debug' )
7
7
const log = debug ( 'cli:object' )
@@ -13,20 +13,29 @@ module.exports = Command.extend({
13
13
options : { } ,
14
14
15
15
run : ( key ) => {
16
- var node = new IPFS ( )
16
+ var ipfs = utils . getIPFS ( )
17
17
18
18
if ( ! key ) {
19
19
throw new Error ( "Argument 'key' is required" )
20
20
}
21
21
22
- const mh = new Buffer ( bs58 . decode ( key ) )
23
- node . object . data ( mh , ( err , data ) => {
22
+ const mh = utils . isDaemonOn ( )
23
+ ? key
24
+ : new Buffer ( bs58 . decode ( key ) )
25
+
26
+ ipfs . object . data ( mh , ( err , data ) => {
24
27
if ( err ) {
25
28
log . error ( err )
26
29
throw err
27
30
}
28
31
29
- console . log ( data . toString ( ) )
32
+ if ( data instanceof Buffer ) {
33
+ console . log ( data . toString ( ) )
34
+ return
35
+ }
36
+
37
+ // js-ipfs-api output (http stream)
38
+ data . pipe ( process . stdout )
30
39
} )
31
40
}
32
41
} )
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const Command = require ( 'ronin' ) . Command
4
- const IPFS = require ( '../../../ipfs-core ' )
4
+ const utils = require ( '../../utils ' )
5
5
const bs58 = require ( 'bs58' )
6
6
const debug = require ( 'debug' )
7
7
const log = debug ( 'cli:object' )
@@ -13,14 +13,25 @@ module.exports = Command.extend({
13
13
options : { } ,
14
14
15
15
run : ( key ) => {
16
- var node = new IPFS ( )
16
+ var ipfs = utils . getIPFS ( )
17
17
18
18
if ( ! key ) {
19
19
throw new Error ( "Argument 'key' is required" )
20
20
}
21
21
22
+ if ( utils . isDaemonOn ( ) ) {
23
+ return ipfs . object . get ( key , ( err , obj ) => {
24
+ if ( err ) {
25
+ log . error ( err )
26
+ throw err
27
+ }
28
+
29
+ console . log ( JSON . stringify ( obj ) )
30
+ } )
31
+ }
32
+
22
33
const mh = new Buffer ( bs58 . decode ( key ) )
23
- node . object . get ( mh , ( err , obj ) => {
34
+ ipfs . object . get ( mh , ( err , obj ) => {
24
35
if ( err ) {
25
36
log . error ( err )
26
37
throw err
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const Command = require ( 'ronin' ) . Command
4
- const IPFS = require ( '../../../ipfs-core ' )
4
+ const utils = require ( '../../utils ' )
5
5
const bs58 = require ( 'bs58' )
6
6
const debug = require ( 'debug' )
7
7
const log = debug ( 'cli:object' )
@@ -13,19 +13,29 @@ module.exports = Command.extend({
13
13
options : { } ,
14
14
15
15
run : ( key ) => {
16
- var node = new IPFS ( )
16
+ var ipfs = utils . getIPFS ( )
17
17
18
18
if ( ! key ) {
19
19
throw new Error ( "Argument 'key' is required" )
20
20
}
21
21
22
- const mh = new Buffer ( bs58 . decode ( key ) )
23
- node . object . links ( mh , ( err , links ) => {
22
+ const mh = utils . isDaemonOn ( )
23
+ ? key
24
+ : new Buffer ( bs58 . decode ( key ) )
25
+
26
+ ipfs . object . links ( mh , ( err , links ) => {
24
27
if ( err ) {
25
28
log . error ( err )
26
29
throw err
27
30
}
28
31
32
+ if ( links . Links ) { // js-ipfs-api output
33
+ links . Links . forEach ( ( link ) => {
34
+ console . log ( link . Hash , link . Size , link . Name )
35
+ } )
36
+ return
37
+ }
38
+
29
39
links . forEach ( ( link ) => {
30
40
console . log ( bs58 . encode ( link . hash ) . toString ( ) , link . size , link . name )
31
41
} )
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const Command = require ( 'ronin' ) . Command
4
- const IPFS = require ( '../../../ipfs-core ' )
4
+ const utils = require ( '../../utils ' )
5
5
const bs58 = require ( 'bs58' )
6
6
const debug = require ( 'debug' )
7
7
const log = debug ( 'cli:object' )
@@ -13,14 +13,19 @@ module.exports = Command.extend({
13
13
options : { } ,
14
14
15
15
run : ( template ) => {
16
- var node = new IPFS ( )
16
+ var ipfs = utils . getIPFS ( )
17
17
18
- node . object . new ( template , ( err , obj ) => {
18
+ ipfs . object . new ( template , ( err , obj ) => {
19
19
if ( err ) {
20
20
log . error ( err )
21
21
throw err
22
22
}
23
23
24
+ if ( typeof obj . Hash === 'string' ) { // js-ipfs-api output
25
+ console . log ( obj . Hash )
26
+ return
27
+ }
28
+
24
29
console . log ( bs58 . encode ( obj . Hash ) . toString ( ) )
25
30
} )
26
31
}
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const Command = require ( 'ronin' ) . Command
4
- const IPFS = require ( '../../../ipfs-core ' )
4
+ const utils = require ( '../../utils ' )
5
5
const bs58 = require ( 'bs58' )
6
6
const bl = require ( 'bl' )
7
7
const fs = require ( 'fs' )
@@ -17,9 +17,20 @@ module.exports = Command.extend({
17
17
options : { } ,
18
18
19
19
run : ( filePath ) => {
20
- var node = new IPFS ( )
20
+ var ipfs = utils . getIPFS ( )
21
21
22
22
function parseAndAddNode ( buf ) {
23
+ if ( utils . isDaemonOn ( ) ) {
24
+ return ipfs . object . put ( buf , 'json' , ( err , obj ) => {
25
+ if ( err ) {
26
+ log . error ( err )
27
+ throw err
28
+ }
29
+
30
+ console . log ( 'added' , obj . Hash )
31
+ } )
32
+ }
33
+
23
34
let parsed
24
35
try {
25
36
parsed = JSON . parse ( buf . toString ( ) )
@@ -38,7 +49,7 @@ module.exports = Command.extend({
38
49
39
50
const dagNode = new DAGNode ( data , links )
40
51
41
- node . object . put ( dagNode , ( err , obj ) => {
52
+ ipfs . object . put ( dagNode , ( err , obj ) => {
42
53
if ( err ) {
43
54
log . error ( err )
44
55
throw err
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const Command = require ( 'ronin' ) . Command
4
- const IPFS = require ( '../../../ipfs-core ' )
4
+ const utils = require ( '../../utils ' )
5
5
const bs58 = require ( 'bs58' )
6
6
const debug = require ( 'debug' )
7
7
const log = debug ( 'cli:object' )
@@ -13,19 +13,24 @@ module.exports = Command.extend({
13
13
options : { } ,
14
14
15
15
run : ( key ) => {
16
- var node = new IPFS ( )
16
+ var ipfs = utils . getIPFS ( )
17
17
18
18
if ( ! key ) {
19
19
throw new Error ( "Argument 'key' is required" )
20
20
}
21
21
22
- const mh = new Buffer ( bs58 . decode ( key ) )
23
- node . object . stat ( mh , ( err , stats ) => {
22
+ const mh = utils . isDaemonOn ( )
23
+ ? key
24
+ : new Buffer ( bs58 . decode ( key ) )
25
+
26
+ ipfs . object . stat ( mh , ( err , stats ) => {
24
27
if ( err ) {
25
28
log . error ( err )
26
29
throw err
27
30
}
28
31
32
+ delete stats . Hash // only for js-ipfs-api output
33
+
29
34
Object . keys ( stats ) . forEach ( ( key ) => {
30
35
console . log ( `${ key } : ${ stats [ key ] } ` )
31
36
} )
You can’t perform that action at this time.
0 commit comments