mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-13 15:03:09 +02:00
54 lines
1.3 KiB
TypeScript
54 lines
1.3 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';
|
|
|
|
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,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const instance = await this.metaService.fetch(true);
|
|
|
|
// Calculate drive usage
|
|
const usage = await this.driveFileEntityService.calcDriveUsageOf(me.id);
|
|
|
|
return {
|
|
capacity: 1024 * 1024 * (me.driveCapacityOverrideMb ?? instance.localDriveCapacityMb),
|
|
usage: usage,
|
|
};
|
|
});
|
|
}
|
|
}
|