mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-30 09:53:02 +00:00
This commit is contained in:
parent
3e08c670fb
commit
434bced6f4
2 changed files with 28 additions and 20 deletions
|
@ -79,17 +79,20 @@ export default (
|
|||
}
|
||||
}
|
||||
|
||||
// Fetch all files to calculate drive usage
|
||||
const files = await DriveFile
|
||||
.find({ user_id: user._id }, {
|
||||
fields: {
|
||||
datasize: true,
|
||||
_id: false
|
||||
}
|
||||
});
|
||||
|
||||
// Calculate drive usage (in byte)
|
||||
const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0);
|
||||
// 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;
|
||||
|
||||
log(`drive usage is ${usage}`);
|
||||
|
||||
|
|
|
@ -15,15 +15,20 @@ import DriveFile from '../models/drive-file';
|
|||
module.exports = (params, user) =>
|
||||
new Promise(async (res, rej) =>
|
||||
{
|
||||
// Fetch all files to calculate drive usage
|
||||
const files = await DriveFile
|
||||
.find({ user_id: user._id }, {
|
||||
datasize: true,
|
||||
_id: false
|
||||
});
|
||||
|
||||
// Calculate drive usage (in byte)
|
||||
const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0);
|
||||
// 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,
|
||||
|
|
Loading…
Reference in a new issue