This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +41
-15
lines changed Expand file tree Collapse file tree 5 files changed +41
-15
lines changed Original file line number Diff line number Diff line change 104104 "ipfs-http-response" : " ~0.4.0" ,
105105 "ipfs-mfs" : " ^0.13.0" ,
106106 "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 " ,
108108 "ipfs-unixfs" : " ~0.1.16" ,
109109 "ipfs-unixfs-exporter" : " ^0.38.0" ,
110110 "ipfs-unixfs-importer" : " ^0.40.0" ,
Original file line number Diff line number Diff line change 11'use strict'
22
3+ const prettyBytes = require ( 'pretty-bytes' )
4+
35module . exports = {
46 command : 'stat' ,
57
@@ -15,14 +17,23 @@ module.exports = {
1517
1618 handler ( argv ) {
1719 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 } ` )
2637 } ) ( ) )
2738 }
2839}
Original file line number Diff line number Diff line change @@ -40,10 +40,8 @@ module.exports = function repo (self) {
4040
4141 gc : require ( './pin/gc' ) ( self ) ,
4242
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 ( )
4745
4846 return {
4947 numObjects : stats . numObjects ,
Original file line number Diff line number Diff line change @@ -35,8 +35,7 @@ exports.version = async (request, h) => {
3535
3636exports . stat = async ( request , h ) => {
3737 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 ( )
4039
4140 return h . response ( {
4241 NumObjects : stat . numObjects ,
Original file line number Diff line number Diff line change @@ -12,6 +12,24 @@ describe('repo', () => runOnAndOff((thing) => {
1212 ipfs = thing . ipfs
1313 } )
1414
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+
1533 it ( 'get the repo version' , async ( ) => {
1634 const out = await ipfs ( 'repo version' )
1735 expect ( out ) . to . eql ( `${ repoVersion } \n` )
You can’t perform that action at this time.
0 commit comments