1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-26 04:28:17 +09:00
MisskeyIO/src/server/api/endpoints/drive.ts

38 lines
612 B
TypeScript
Raw Normal View History

2016-12-29 07:49:51 +09:00
/**
* Module dependencies
*/
2018-03-29 20:32:18 +09:00
import DriveFile from '../../../models/drive-file';
2016-12-29 07:49:51 +09:00
/**
* Get drive information
*
2017-03-01 17:37:01 +09:00
* @param {any} params
* @param {any} user
* @return {Promise<any>}
2016-12-29 07:49:51 +09:00
*/
2017-03-04 04:28:38 +09:00
module.exports = (params, user) => new Promise(async (res, rej) => {
// Calculate drive usage
const usage = ((await DriveFile
.aggregate([
2018-03-29 14:48:47 +09:00
{ $match: { 'metadata.userId': user._id } },
2017-03-04 04:28:38 +09:00
{
$project: {
2017-11-06 15:18:45 +09:00
length: true
2017-03-04 04:28:38 +09:00
}
},
{
$group: {
_id: null,
2017-11-06 15:18:45 +09:00
usage: { $sum: '$length' }
2017-03-01 17:37:01 +09:00
}
2017-03-04 04:28:38 +09:00
}
]))[0] || {
usage: 0
}).usage;
2016-12-29 07:49:51 +09:00
2017-03-04 04:28:38 +09:00
res({
2018-03-29 14:48:47 +09:00
capacity: user.driveCapacity,
2017-03-04 04:28:38 +09:00
usage: usage
2016-12-29 07:49:51 +09:00
});
2017-03-04 04:28:38 +09:00
});