2016-12-28 16:49:51 -06:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
2017-02-13 15:42:01 -06:00
|
|
|
import DriveFile from '../models/drive-file';
|
2016-12-28 16:49:51 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get drive information
|
|
|
|
*
|
|
|
|
* @param {Object} params
|
|
|
|
* @param {Object} user
|
|
|
|
* @return {Promise<object>}
|
|
|
|
*/
|
|
|
|
module.exports = (params, user) =>
|
|
|
|
new Promise(async (res, rej) =>
|
|
|
|
{
|
2017-02-13 17:24:18 -06:00
|
|
|
// 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 16:49:51 -06:00
|
|
|
|
|
|
|
res({
|
|
|
|
capacity: user.drive_capacity,
|
|
|
|
usage: usage
|
|
|
|
});
|
|
|
|
});
|