monkeeShark/src/server/api/endpoints/drive.ts
2018-06-15 09:56:59 +09:00

35 lines
630 B
TypeScript

import DriveFile from '../../../models/drive-file';
/**
* Get drive information
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Calculate drive usage
const usage = await DriveFile
.aggregate([{
$match: {
'metadata.userId': user._id,
'metadata.deletedAt': { $exists: false }
}
}, {
$project: {
length: true
}
}, {
$group: {
_id: null,
usage: { $sum: '$length' }
}
}])
.then((aggregates: any[]) => {
if (aggregates.length > 0) {
return aggregates[0].usage;
}
return 0;
});
res({
capacity: user.driveCapacity,
usage: usage
});
});