mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-17 11:08:58 +01:00
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import { MetaService } from '@/core/MetaService.js';
|
|
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
|
|
import { RoleService } from '@/core/RoleService.js';
|
|
|
|
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
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
constructor(
|
|
private metaService: MetaService,
|
|
private driveFileEntityService: DriveFileEntityService,
|
|
private roleService: RoleService,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const instance = await this.metaService.fetch(true);
|
|
|
|
// Calculate drive usage
|
|
const usage = await this.driveFileEntityService.calcDriveUsageOf(me.id);
|
|
|
|
const policies = await this.roleService.getUserPolicies(me.id);
|
|
|
|
return {
|
|
capacity: 1024 * 1024 * policies.driveCapacityMb,
|
|
usage: usage,
|
|
};
|
|
});
|
|
}
|
|
}
|