Skip to content

Commit d9418e2

Browse files
committed
Add network information to /list
1 parent c849a01 commit d9418e2

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ const Status = {
2121
class Hypermount {
2222
constructor (store) {
2323
this.store = store
24+
this.drives = new Map()
2425
}
2526

26-
mount (key, mnt, opts) {
27+
async mount (key, mnt, opts) {
2728
if (typeof opts === 'function') return this.mount(key, mnt, null, opts)
2829
opts = opts || {}
2930

@@ -38,7 +39,10 @@ class Hypermount {
3839
sparseMetadata: (opts.sparseMetadata !== undefined) ? opts.sparseMetadata : true
3940
})
4041

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
4246
}
4347

4448
unmount (mnt) {
@@ -83,7 +87,6 @@ async function start () {
8387

8488
app.post('/mount', async (req, res) => {
8589
try {
86-
console.log('req.body:', req.body)
8790
let { key, mnt } = req.body
8891
key = await mount(hypermount, db, key, mnt, req.body)
8992
return res.status(201).json({ key, mnt })
@@ -121,7 +124,7 @@ async function start () {
121124

122125
app.get('/list', async (req, res) => {
123126
try {
124-
let result = await list(db)
127+
let result = await list(hypermount, db)
125128
return res.json(result)
126129
} catch (err) {
127130
console.error('List error:', err)
@@ -145,12 +148,17 @@ async function start () {
145148
}
146149
}
147150

148-
function list (db) {
151+
function list (hypermount, db) {
149152
return new Promise((resolve, reject) => {
150153
const result = {}
151154
const stream = db.createReadStream()
152155
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+
}
154162
})
155163
stream.on('end', () => {
156164
return resolve(result)
@@ -188,7 +196,6 @@ function unmountAll (hypermount, db) {
188196
db.createReadStream(),
189197
through.obj(({ key, value: record }, enc, cb) => {
190198
if (record.status === Status.MOUNTED) {
191-
console.log('UNMOUNTING in unmountAll:', key)
192199
let unmountPromise = unmount(hypermount, db, key)
193200
unmountPromise.then(() => cb(null))
194201
unmountPromise.catch(err => cb(err))

0 commit comments

Comments
 (0)