This commit is contained in:
tamaina 2023-05-29 14:17:25 +00:00
parent a1c96d9bcb
commit 9135d2757e
3 changed files with 55 additions and 43 deletions

View File

@ -3,38 +3,15 @@ import { DataSource } from 'typeorm';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
export const meta = {
requireCredential: true,
requireAdmin: true,
tags: ['admin'],
res: {
type: 'object',
optional: false, nullable: false,
example: {
migrations: {
count: 66,
size: 32768,
},
},
},
} 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> {
export default class extends Endpoint<'admin/get-table-stats'> {
name = 'admin/get-table-stats' as const;
constructor(
@Inject(DI.db)
private db: DataSource,
) {
super(meta, paramDef, async () => {
super(async () => {
const sizes = await this.db.query(`
SELECT relname AS "table", reltuples as "count", pg_total_relation_size(C.oid) AS "size"
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)

View File

@ -3,29 +3,15 @@ import type { UserIpsRepository } from '@/models/index.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
} as const;
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },
},
required: ['userId'],
} as const;
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
export default class extends Endpoint<'admin/get-user-ips'> {
name = 'admin/get-user-ips' as const;
constructor(
@Inject(DI.userIpsRepository)
private userIpsRepository: UserIpsRepository,
) {
super(meta, paramDef, async (ps, me) => {
super(async (ps, me) => {
const ips = await this.userIpsRepository.find({
where: { userId: ps.userId },
order: { createdAt: 'DESC' },

View File

@ -1482,6 +1482,55 @@ export const endpoints = {
tablename: { type: 'string' },
indexname: { type: 'string' },
},
required: ['tablename', 'indexname'],
},
},
}],
},
'admin/get-table-stats': {
requireCredential: true,
requireAdmin: true,
tags: ['admin'],
defines: [{
req: undefined,
res: {
type: 'object',
additionalProperties: {
type: 'object',
properties: {
count: { type: 'number' },
size: { type: 'number' },
},
required: ['count', 'size'],
},
},
}],
},
'admin/get-user-ips': {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
defines: [{
req: {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },
},
required: ['userId'],
},
res: {
type: 'array',
items: {
type: 'object',
properties: {
ip: { type: 'string' },
createdAt: { type: 'string', format: 'date-time' },
},
required: ['ip', 'createdAt'],
},
},
}],