rudeshark.net/packages/backend/src/server/api/endpoints/drive.ts
tamaina fcfb5ef0a3
Fix ajv (#8333)
* wip

* ✌️

* use ajv/dist/core

* revert try

* clean up
2022-02-20 13:15:40 +09:00

46 lines
901 B
TypeScript

import define from '../define';
import { fetchMeta } from '@/misc/fetch-meta';
import { DriveFiles } from '@/models/index';
export const meta = {
tags: ['drive', 'account'],
requireCredential: true,
kind: 'read:drive',
res: {
type: 'object',
optional: false, nullable: false,
properties: {
capacity: {
type: 'number',
optional: false, nullable: false,
},
usage: {
type: 'number',
optional: false, nullable: false,
},
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, 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,
};
});