From 9135d2757e2b7dfb72467f5ee48f5826ba364d54 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 29 May 2023 14:17:25 +0000 Subject: [PATCH] wip --- .../api/endpoints/admin/get-table-stats.ts | 29 ++--------- .../api/endpoints/admin/get-user-ips.ts | 20 ++------ packages/misskey-js/src/endpoints.ts | 49 +++++++++++++++++++ 3 files changed, 55 insertions(+), 43 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/admin/get-table-stats.ts b/packages/backend/src/server/api/endpoints/admin/get-table-stats.ts index 09d61bd74..c26c571a3 100644 --- a/packages/backend/src/server/api/endpoints/admin/get-table-stats.ts +++ b/packages/backend/src/server/api/endpoints/admin/get-table-stats.ts @@ -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 { +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) diff --git a/packages/backend/src/server/api/endpoints/admin/get-user-ips.ts b/packages/backend/src/server/api/endpoints/admin/get-user-ips.ts index bfcc8a700..4d9abe10f 100644 --- a/packages/backend/src/server/api/endpoints/admin/get-user-ips.ts +++ b/packages/backend/src/server/api/endpoints/admin/get-user-ips.ts @@ -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 { +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' }, diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index 99a87c581..9757dc05d 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -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'], }, }, }],