mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 11:43:08 +02:00
2756f553c6
* wip
* wip
* wip
* Update attached_notes.ts
* wip
* Refactor
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* Update call.ts
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* ✌️
* Fix
46 lines
882 B
TypeScript
46 lines
882 B
TypeScript
import DriveFile from '../../../models/drive-file';
|
|
import define from '../define';
|
|
import fetchMeta from '../../../misc/fetch-meta';
|
|
|
|
export const meta = {
|
|
desc: {
|
|
'ja-JP': 'ドライブの情報を取得します。',
|
|
'en-US': 'Get drive information.'
|
|
},
|
|
|
|
requireCredential: true,
|
|
|
|
kind: 'drive-read'
|
|
};
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
const instance = await fetchMeta();
|
|
|
|
// Calculate drive usage
|
|
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;
|
|
}
|
|
return 0;
|
|
});
|
|
|
|
return {
|
|
capacity: 1024 * 1024 * instance.localDriveCapacityMb,
|
|
usage: usage
|
|
};
|
|
});
|