From 0e4a111f81cceed275d9bec2695f6e401fb654d8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 12 Nov 2021 02:02:25 +0900 Subject: refactoring Resolve #7779 --- packages/backend/src/server/api/endpoints/drive.ts | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 packages/backend/src/server/api/endpoints/drive.ts (limited to 'packages/backend/src/server/api/endpoints/drive.ts') diff --git a/packages/backend/src/server/api/endpoints/drive.ts b/packages/backend/src/server/api/endpoints/drive.ts new file mode 100644 index 0000000000..2974ccfab9 --- /dev/null +++ b/packages/backend/src/server/api/endpoints/drive.ts @@ -0,0 +1,38 @@ +import define from '../define'; +import { fetchMeta } from '@/misc/fetch-meta'; +import { DriveFiles } from '@/models/index'; + +export const meta = { + tags: ['drive', 'account'], + + requireCredential: true as const, + + kind: 'read:drive', + + res: { + type: 'object' as const, + optional: false as const, nullable: false as const, + properties: { + capacity: { + type: 'number' as const, + optional: false as const, nullable: false as const, + }, + usage: { + type: 'number' as const, + optional: false as const, nullable: false as const, + } + } + } +}; + +export default define(meta, async (ps, user) => { + const instance = await fetchMeta(true); + + // Calculate drive usage + const usage = await DriveFiles.calcDriveUsageOf(user.id); + + return { + capacity: 1024 * 1024 * instance.localDriveCapacityMb, + usage: usage + }; +}); -- cgit v1.2.3-freya