mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 21:23:08 +02:00
37 lines
612 B
TypeScript
37 lines
612 B
TypeScript
/**
|
|
* 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: { 'metadata.userId': user._id } },
|
|
{
|
|
$project: {
|
|
length: true
|
|
}
|
|
},
|
|
{
|
|
$group: {
|
|
_id: null,
|
|
usage: { $sum: '$length' }
|
|
}
|
|
}
|
|
]))[0] || {
|
|
usage: 0
|
|
}).usage;
|
|
|
|
res({
|
|
capacity: user.driveCapacity,
|
|
usage: usage
|
|
});
|
|
});
|