rudeshark.net/src/api/endpoints/drive.js
2017-03-01 17:37:01 +09:00

41 lines
640 B
JavaScript

'use strict';
/**
* Module dependencies
*/
import DriveFile from '../models/drive-file';
/**
* Get drive information
*
* @param {any} params
* @param {any} user
* @return {Promise<any>}
*/
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' }
}
}
]))[0] || {
usage: 0
}).usage;
res({
capacity: user.drive_capacity,
usage: usage
});
});