2016-12-28 22:49:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
2017-02-13 21:42:01 +00:00
|
|
|
import DriveFile from '../models/drive-file';
|
2016-12-28 22:49:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get drive information
|
|
|
|
*
|
2017-03-01 08:37:01 +00:00
|
|
|
* @param {any} params
|
|
|
|
* @param {any} user
|
|
|
|
* @return {Promise<any>}
|
2016-12-28 22:49:51 +00:00
|
|
|
*/
|
|
|
|
module.exports = (params, user) =>
|
2017-03-01 08:37:01 +00:00
|
|
|
new Promise(async (res, rej) => {
|
|
|
|
// Calculate drive usage
|
|
|
|
const usage = ((await DriveFile
|
|
|
|
.aggregate([
|
|
|
|
{ $match: { user_id: user._id } },
|
|
|
|
{
|
|
|
|
$project: {
|
|
|
|
datasize: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
$group: {
|
|
|
|
_id: null,
|
|
|
|
usage: { $sum: '$datasize' }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]))[0] || {
|
|
|
|
usage: 0
|
|
|
|
}).usage;
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-03-01 08:37:01 +00:00
|
|
|
res({
|
|
|
|
capacity: user.drive_capacity,
|
|
|
|
usage: usage
|
|
|
|
});
|
2016-12-28 22:49:51 +00:00
|
|
|
});
|