paricafe/src/api/endpoints/drive.ts

38 lines
601 B
TypeScript
Raw Normal View History

2016-12-28 16:49:51 -06:00
/**
* 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
*
2017-03-01 02:37:01 -06:00
* @param {any} params
* @param {any} user
* @return {Promise<any>}
2016-12-28 16:49:51 -06:00
*/
2017-03-03 13:28:38 -06:00
module.exports = (params, user) => 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' }
2017-03-01 02:37:01 -06:00
}
2017-03-03 13:28:38 -06:00
}
]))[0] || {
usage: 0
}).usage;
2016-12-28 16:49:51 -06:00
2017-03-03 13:28:38 -06:00
res({
capacity: user.drive_capacity,
usage: usage
2016-12-28 16:49:51 -06:00
});
2017-03-03 13:28:38 -06:00
});