2023-07-27 00:31:52 -05:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-02-16 08:09:41 -06:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-09-17 13:27:08 -05:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { MetaService } from '@/core/MetaService.js';
|
|
|
|
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
|
2023-01-12 06:02:26 -06:00
|
|
|
import { RoleService } from '@/core/RoleService.js';
|
2016-12-28 16:49:51 -06:00
|
|
|
|
2018-07-16 14:36:44 -05:00
|
|
|
export const meta = {
|
2019-02-22 20:20:58 -06:00
|
|
|
tags: ['drive', 'account'],
|
|
|
|
|
2022-01-18 07:27:10 -06:00
|
|
|
requireCredential: true,
|
2018-07-16 14:36:44 -05:00
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
kind: 'read:drive',
|
2019-02-24 12:21:54 -06:00
|
|
|
|
|
|
|
res: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 12:21:54 -06:00
|
|
|
properties: {
|
|
|
|
capacity: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 12:21:54 -06:00
|
|
|
},
|
|
|
|
usage: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 08:58:30 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 07:27:10 -06:00
|
|
|
} as const;
|
2018-07-16 14:36:44 -05:00
|
|
|
|
2022-02-19 22:15:40 -06:00
|
|
|
export const paramDef = {
|
2022-02-18 23:05:32 -06:00
|
|
|
type: 'object',
|
|
|
|
properties: {},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
2022-09-17 13:27:08 -05:00
|
|
|
@Injectable()
|
2023-08-17 07:20:58 -05:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2022-09-17 13:27:08 -05:00
|
|
|
constructor(
|
|
|
|
private metaService: MetaService,
|
|
|
|
private driveFileEntityService: DriveFileEntityService,
|
2023-01-12 06:02:26 -06:00
|
|
|
private roleService: RoleService,
|
2022-09-17 13:27:08 -05:00
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const instance = await this.metaService.fetch(true);
|
|
|
|
|
|
|
|
// Calculate drive usage
|
|
|
|
const usage = await this.driveFileEntityService.calcDriveUsageOf(me.id);
|
|
|
|
|
2023-01-15 05:52:53 -06:00
|
|
|
const policies = await this.roleService.getUserPolicies(me.id);
|
2023-01-12 06:02:26 -06:00
|
|
|
|
2022-09-17 13:27:08 -05:00
|
|
|
return {
|
2023-01-15 05:52:53 -06:00
|
|
|
capacity: 1024 * 1024 * policies.driveCapacityMb,
|
2022-09-17 13:27:08 -05:00
|
|
|
usage: usage,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|