summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/drive.ts
blob: 9b723a054243ef562fa5a261d72e660760224397 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import define from '../define';
import { fetchMeta } from '../../../misc/fetch-meta';
import { DriveFiles } from '../../../models';

export const meta = {
	desc: {
		'ja-JP': 'ドライブの情報を取得します。',
		'en-US': 'Get drive information.'
	},

	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.clacDriveUsageOf(user);

	return {
		capacity: 1024 * 1024 * instance.localDriveCapacityMb,
		usage: usage
	};
});