@@ -21,9 +21,10 @@ const Status = {
21
21
class Hypermount {
22
22
constructor ( store ) {
23
23
this . store = store
24
+ this . drives = new Map ( )
24
25
}
25
26
26
- mount ( key , mnt , opts ) {
27
+ async mount ( key , mnt , opts ) {
27
28
if ( typeof opts === 'function' ) return this . mount ( key , mnt , null , opts )
28
29
opts = opts || { }
29
30
@@ -38,7 +39,10 @@ class Hypermount {
38
39
sparseMetadata : ( opts . sparseMetadata !== undefined ) ? opts . sparseMetadata : true
39
40
} )
40
41
41
- return hyperfuse . mount ( drive , mnt )
42
+ const mountInfo = await hyperfuse . mount ( drive , mnt )
43
+ this . drives . set ( mountInfo . key , drive )
44
+
45
+ return mountInfo
42
46
}
43
47
44
48
unmount ( mnt ) {
@@ -83,7 +87,6 @@ async function start () {
83
87
84
88
app . post ( '/mount' , async ( req , res ) => {
85
89
try {
86
- console . log ( 'req.body:' , req . body )
87
90
let { key, mnt } = req . body
88
91
key = await mount ( hypermount , db , key , mnt , req . body )
89
92
return res . status ( 201 ) . json ( { key, mnt } )
@@ -121,7 +124,7 @@ async function start () {
121
124
122
125
app . get ( '/list' , async ( req , res ) => {
123
126
try {
124
- let result = await list ( db )
127
+ let result = await list ( hypermount , db )
125
128
return res . json ( result )
126
129
} catch ( err ) {
127
130
console . error ( 'List error:' , err )
@@ -145,12 +148,17 @@ async function start () {
145
148
}
146
149
}
147
150
148
- function list ( db ) {
151
+ function list ( hypermount , db ) {
149
152
return new Promise ( ( resolve , reject ) => {
150
153
const result = { }
151
154
const stream = db . createReadStream ( )
152
155
stream . on ( 'data' , ( { key : mnt , value : record } ) => {
153
- result [ record . key ] = mnt
156
+ const entry = result [ record . key ] = { mnt }
157
+ const drive = hypermount . drives . get ( record . key )
158
+ entry . networking = {
159
+ metadata : drive . metadata . stats ,
160
+ content : drive . content && drive . content . stats
161
+ }
154
162
} )
155
163
stream . on ( 'end' , ( ) => {
156
164
return resolve ( result )
@@ -188,7 +196,6 @@ function unmountAll (hypermount, db) {
188
196
db . createReadStream ( ) ,
189
197
through . obj ( ( { key, value : record } , enc , cb ) => {
190
198
if ( record . status === Status . MOUNTED ) {
191
- console . log ( 'UNMOUNTING in unmountAll:' , key )
192
199
let unmountPromise = unmount ( hypermount , db , key )
193
200
unmountPromise . then ( ( ) => cb ( null ) )
194
201
unmountPromise . catch ( err => cb ( err ) )
0 commit comments