2016-12-28 15:49:51 -07:00
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
2018-03-29 05:32:18 -06:00
|
|
|
import DriveFile from '../../../models/drive-file';
|
2016-12-28 15:49:51 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get drive information
|
|
|
|
*
|
2017-03-01 01:37:01 -07:00
|
|
|
* @param {any} params
|
|
|
|
* @param {any} user
|
|
|
|
* @return {Promise<any>}
|
2016-12-28 15:49:51 -07:00
|
|
|
*/
|
2017-03-03 12:28:38 -07:00
|
|
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
|
|
|
// Calculate drive usage
|
|
|
|
const usage = ((await DriveFile
|
|
|
|
.aggregate([
|
2018-03-28 23:48:47 -06:00
|
|
|
{ $match: { 'metadata.userId': user._id } },
|
2017-03-03 12:28:38 -07:00
|
|
|
{
|
|
|
|
$project: {
|
2017-11-05 23:18:45 -07:00
|
|
|
length: true
|
2017-03-03 12:28:38 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
$group: {
|
|
|
|
_id: null,
|
2017-11-05 23:18:45 -07:00
|
|
|
usage: { $sum: '$length' }
|
2017-03-01 01:37:01 -07:00
|
|
|
}
|
2017-03-03 12:28:38 -07:00
|
|
|
}
|
|
|
|
]))[0] || {
|
|
|
|
usage: 0
|
|
|
|
}).usage;
|
2016-12-28 15:49:51 -07:00
|
|
|
|
2017-03-03 12:28:38 -07:00
|
|
|
res({
|
2018-03-28 23:48:47 -06:00
|
|
|
capacity: user.driveCapacity,
|
2017-03-03 12:28:38 -07:00
|
|
|
usage: usage
|
2016-12-28 15:49:51 -07:00
|
|
|
});
|
2017-03-03 12:28:38 -07:00
|
|
|
});
|