File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ const request = require ( 'request-promise-native' )
2
+ const chalk = require ( 'chalk' )
3
+
4
+ const { loadMetadata } = require ( '../lib/metadata' )
5
+
6
+ exports . command = 'list'
7
+ exports . desc = 'List all mounted Hyperdrives.'
8
+ exports . handler = async function ( argv ) {
9
+ try {
10
+ let metadata = await loadMetadata ( )
11
+ let rsp = await request . get ( new URL ( '/list' , metadata . endpoint ) . toString ( ) , {
12
+ auth : {
13
+ bearer : metadata . token
14
+ } ,
15
+ resolveWithFullResponse : true ,
16
+ json : true
17
+ } )
18
+ if ( rsp . statusCode === 200 ) {
19
+ for ( let key of Object . keys ( rsp . body ) ) {
20
+ const { mnt, networking } = rsp . body [ key ]
21
+ console . log ( `${ chalk . green ( key ) } => ${ chalk . green ( mnt ) } ` )
22
+ console . log ( ` Network Stats:` )
23
+ console . log ( ` Metadata:` )
24
+ console . log ( ` Uploaded: ${ networking . metadata . totals . uploadedBytes / 1e6 } MB` )
25
+ console . log ( ` Downloaded: ${ networking . metadata . totals . downloadedBytes / 1e6 } MB` )
26
+ console . log ( ` Content:` )
27
+ console . log ( ` Uploaded: ${ networking . content . totals . uploadedBytes / 1e6 } MB` )
28
+ console . log ( ` Downloaded: ${ networking . content . totals . downloadedBytes / 1e6 } MB` )
29
+ }
30
+ } else {
31
+ console . log ( chalk . orange ( 'Cannot get the deamon\'s mount list.' ) )
32
+ }
33
+ } catch ( err ) {
34
+ console . error ( chalk . red ( `Could not get server status: ${ err } ` ) )
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments