This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 5 files changed +41
-15
lines changed 5 files changed +41
-15
lines changed Original file line number Diff line number Diff line change 104
104
"ipfs-http-response" : " ~0.4.0" ,
105
105
"ipfs-mfs" : " ^0.13.0" ,
106
106
"ipfs-multipart" : " ^0.2.0" ,
107
- "ipfs-repo" : " ^0.29.0 " ,
107
+ "ipfs-repo" : " github:ipfs/js-ipfs-repo#feat/remove-options-object-from-stat " ,
108
108
"ipfs-unixfs" : " ~0.1.16" ,
109
109
"ipfs-unixfs-exporter" : " ^0.38.0" ,
110
110
"ipfs-unixfs-importer" : " ^0.40.0" ,
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
+ const prettyBytes = require ( 'pretty-bytes' )
4
+
3
5
module . exports = {
4
6
command : 'stat' ,
5
7
@@ -15,14 +17,23 @@ module.exports = {
15
17
16
18
handler ( argv ) {
17
19
argv . resolve ( ( async ( ) => {
18
- const ipfs = await argv . getIpfs ( )
19
- const stats = await ipfs . repo . stat ( { human : argv . human } )
20
- argv . print ( `repo status
21
- number of objects: ${ stats . numObjects }
22
- repo size: ${ stats . repoSize }
23
- repo path: ${ stats . repoPath }
24
- version: ${ stats . version }
25
- maximum storage: ${ stats . storageMax } ` )
20
+ const { getIpfs, human } = argv
21
+
22
+ const ipfs = await getIpfs ( )
23
+ const stats = await ipfs . repo . stat ( )
24
+
25
+ if ( human ) {
26
+ stats . numObjects = stats . numObjects . toNumber ( )
27
+ stats . repoSize = prettyBytes ( stats . repoSize . toNumber ( ) ) . toUpperCase ( )
28
+ stats . storageMax = prettyBytes ( stats . storageMax . toNumber ( ) ) . toUpperCase ( )
29
+ }
30
+
31
+ argv . print (
32
+ `NumObjects: ${ stats . numObjects }
33
+ RepoSize: ${ stats . repoSize }
34
+ StorageMax: ${ stats . storageMax }
35
+ RepoPath: ${ stats . repoPath }
36
+ Version: ${ stats . version } ` )
26
37
} ) ( ) )
27
38
}
28
39
}
Original file line number Diff line number Diff line change @@ -40,10 +40,8 @@ module.exports = function repo (self) {
40
40
41
41
gc : require ( './pin/gc' ) ( self ) ,
42
42
43
- stat : callbackify . variadic ( async ( options ) => {
44
- options = options || { }
45
-
46
- const stats = await self . _repo . stat ( options )
43
+ stat : callbackify . variadic ( async ( ) => {
44
+ const stats = await self . _repo . stat ( )
47
45
48
46
return {
49
47
numObjects : stats . numObjects ,
Original file line number Diff line number Diff line change @@ -35,8 +35,7 @@ exports.version = async (request, h) => {
35
35
36
36
exports . stat = async ( request , h ) => {
37
37
const { ipfs } = request . server . app
38
- const human = request . query . human === 'true'
39
- const stat = await ipfs . repo . stat ( { human } )
38
+ const stat = await ipfs . repo . stat ( )
40
39
41
40
return h . response ( {
42
41
NumObjects : stat . numObjects ,
Original file line number Diff line number Diff line change @@ -12,6 +12,24 @@ describe('repo', () => runOnAndOff((thing) => {
12
12
ipfs = thing . ipfs
13
13
} )
14
14
15
+ it ( 'get repo stats' , async ( ) => {
16
+ const stats = await ipfs ( 'repo stat' )
17
+ expect ( stats ) . to . match ( / ^ N u m O b j e c t s : \s \d + $ / m)
18
+ expect ( stats ) . to . match ( / ^ R e p o S i z e : \s \d + $ / m)
19
+ expect ( stats ) . to . match ( / ^ S t o r a g e M a x : \s \d + $ / m)
20
+ expect ( stats ) . to . match ( / ^ R e p o P a t h : \s .+ $ / m)
21
+ expect ( stats ) . to . match ( / ^ V e r s i o n : \s \d + $ / m)
22
+ } )
23
+
24
+ it ( 'get human readable repo stats' , async ( ) => {
25
+ const stats = await ipfs ( 'repo stat --human' )
26
+ expect ( stats ) . to . match ( / ^ N u m O b j e c t s : \s \d + $ / m)
27
+ expect ( stats ) . to . match ( / ^ R e p o S i z e : \s + [ \d . ] + \s [ P T G M K ] ? B $ / gm)
28
+ expect ( stats ) . to . match ( / ^ S t o r a g e M a x : \s + [ \d . ] + \s [ P T G M K ] ? B $ / gm)
29
+ expect ( stats ) . to . match ( / ^ R e p o P a t h : \s .+ $ / m)
30
+ expect ( stats ) . to . match ( / ^ V e r s i o n : \s \d + $ / m)
31
+ } )
32
+
15
33
it ( 'get the repo version' , async ( ) => {
16
34
const out = await ipfs ( 'repo version' )
17
35
expect ( out ) . to . eql ( `${ repoVersion } \n` )
You can’t perform that action at this time.
0 commit comments