summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-06-15 09:56:59 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-06-15 09:56:59 +0900
commitfcd437c89fd429a61e774a59b97c28f16676419d (patch)
tree71ba4b9b43c6550b33aad5ec9f1884ca8c050af2 /src/server/api/endpoints
parent2.40.0 (diff)
downloadsharkey-fcd437c89fd429a61e774a59b97c28f16676419d.tar.gz
sharkey-fcd437c89fd429a61e774a59b97c28f16676419d.tar.bz2
sharkey-fcd437c89fd429a61e774a59b97c28f16676419d.zip
Fix bug
Diffstat (limited to 'src/server/api/endpoints')
-rw-r--r--src/server/api/endpoints/drive.ts44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/server/api/endpoints/drive.ts b/src/server/api/endpoints/drive.ts
index d77ab2bbb0..26944dbc15 100644
--- a/src/server/api/endpoints/drive.ts
+++ b/src/server/api/endpoints/drive.ts
@@ -1,34 +1,32 @@
-/**
- * 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' }
- }
+ const usage = await DriveFile
+ .aggregate([{
+ $match: {
+ 'metadata.userId': user._id,
+ 'metadata.deletedAt': { $exists: false }
+ }
+ }, {
+ $project: {
+ length: true
+ }
+ }, {
+ $group: {
+ _id: null,
+ usage: { $sum: '$length' }
+ }
+ }])
+ .then((aggregates: any[]) => {
+ if (aggregates.length > 0) {
+ return aggregates[0].usage;
}
- ]))[0] || {
- usage: 0
- }).usage;
+ return 0;
+ });
res({
capacity: user.driveCapacity,