2022-09-17 21:27:08 +03:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2022-03-26 08:34:00 +02:00
|
|
|
import { IsNull } from 'typeorm';
|
2022-09-17 21:27:08 +03:00
|
|
|
import { InstancesRepository, NotesRepository, UsersRepository } from '@/models/index.js';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2017-08-12 09:17:03 +03:00
|
|
|
|
2018-11-02 06:47:44 +02:00
|
|
|
export const meta = {
|
2022-01-18 15:27:10 +02:00
|
|
|
requireCredential: false,
|
2018-11-02 06:47:44 +02:00
|
|
|
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['meta'],
|
|
|
|
|
2019-02-24 20:30:22 +02:00
|
|
|
res: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 20:30:22 +02:00
|
|
|
properties: {
|
|
|
|
notesCount: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 20:30:22 +02:00
|
|
|
},
|
|
|
|
originalNotesCount: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 20:30:22 +02:00
|
|
|
},
|
|
|
|
usersCount: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 20:30:22 +02:00
|
|
|
},
|
|
|
|
originalUsersCount: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 20:30:22 +02:00
|
|
|
},
|
|
|
|
instances: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 20:30:22 +02:00
|
|
|
},
|
2021-03-06 15:34:11 +02:00
|
|
|
driveUsageLocal: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 15:34:11 +02:00
|
|
|
},
|
|
|
|
driveUsageRemote: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 16:58:30 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2018-11-02 06:47:44 +02:00
|
|
|
|
2022-02-20 06:15:40 +02:00
|
|
|
export const paramDef = {
|
2022-02-19 07:05:32 +02:00
|
|
|
type: 'object',
|
|
|
|
properties: {},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 19:12:50 +02:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 21:27:08 +03:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.usersRepository)
|
|
|
|
private usersRepository: UsersRepository,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
@Inject(DI.notesRepository)
|
|
|
|
private notesRepository: NotesRepository,
|
|
|
|
|
|
|
|
@Inject(DI.instancesRepository)
|
|
|
|
private instancesRepository: InstancesRepository,
|
|
|
|
|
|
|
|
@Inject(DI.noteReactionsRepository)
|
|
|
|
private noteReactionsRepository: NoteReactionsRepository,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async () => {
|
|
|
|
const [
|
|
|
|
notesCount,
|
|
|
|
originalNotesCount,
|
|
|
|
usersCount,
|
|
|
|
originalUsersCount,
|
|
|
|
reactionsCount,
|
|
|
|
//originalReactionsCount,
|
|
|
|
instances,
|
|
|
|
] = await Promise.all([
|
|
|
|
this.notesRepository.count({ cache: 3600000 }), // 1 hour
|
|
|
|
this.notesRepository.count({ where: { userHost: IsNull() }, cache: 3600000 }),
|
|
|
|
this.usersRepository.count({ cache: 3600000 }),
|
|
|
|
this.usersRepository.count({ where: { host: IsNull() }, cache: 3600000 }),
|
|
|
|
this.noteReactionsRepository.count({ cache: 3600000 }), // 1 hour
|
|
|
|
//this.noteReactionsRepository.count({ where: { userHost: IsNull() }, cache: 3600000 }),
|
|
|
|
this.instancesRepository.count({ cache: 3600000 }),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return {
|
|
|
|
notesCount,
|
|
|
|
originalNotesCount,
|
|
|
|
usersCount,
|
|
|
|
originalUsersCount,
|
|
|
|
reactionsCount,
|
|
|
|
//originalReactionsCount,
|
|
|
|
instances,
|
|
|
|
driveUsageLocal: 0,
|
|
|
|
driveUsageRemote: 0,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|