wildduck/lib/handlers/on-get-quota-root.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

'use strict';
const db = require('../db');
const consts = require('../consts');
module.exports = server => (path, session, callback) => {
server.logger.debug(
{
tnx: 'quota',
cid: session.id
},
'[%s] Requested quota root info for "%s"',
session.id,
path
);
2019-01-24 05:38:29 +08:00
db.database.collection('mailboxes').findOne(
{
user: session.user.id,
path
},
{
maxTimeMS: consts.DB_MAX_TIME_MAILBOXES
2019-01-24 05:38:29 +08:00
},
(err, mailbox) => {
if (err) {
return callback(err);
}
2019-01-24 05:38:29 +08:00
if (!mailbox) {
return callback(null, 'NONEXISTENT');
}
2019-01-24 05:38:29 +08:00
db.users.collection('users').findOne(
{
_id: session.user.id
},
{
maxTimeMS: consts.DB_MAX_TIME_USERS
2019-01-24 05:38:29 +08:00
},
(err, user) => {
if (err) {
return callback(err);
}
if (!user) {
return callback(new Error('User data not found'));
}
return callback(null, {
root: '',
quota: user.quota || server.options.maxStorage || 0,
storageUsed: Math.max(user.storageUsed || 0, 0)
});
}
);
}
);
};