From 68a2aa3efdae5f2424c77dedaef0aa33d9f24cba Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 29 May 2023 16:39:03 +0000 Subject: [PATCH] wip --- .../entities/ModerationLogEntityService.ts | 7 ++- .../endpoints/admin/show-moderation-logs.ts | 61 +------------------ packages/misskey-js/src/endpoints.ts | 24 ++++++++ packages/misskey-js/src/schemas.ts | 2 + .../misskey-js/src/schemas/moderation-log.ts | 30 +++++++++ packages/misskey-js/test-d/schemas.ts | 3 + 6 files changed, 66 insertions(+), 61 deletions(-) create mode 100644 packages/misskey-js/src/schemas/moderation-log.ts diff --git a/packages/backend/src/core/entities/ModerationLogEntityService.ts b/packages/backend/src/core/entities/ModerationLogEntityService.ts index 7058e38af..c4ce5aa75 100644 --- a/packages/backend/src/core/entities/ModerationLogEntityService.ts +++ b/packages/backend/src/core/entities/ModerationLogEntityService.ts @@ -6,6 +6,8 @@ import type { } from '@/models/entities/Blocking.js'; import type { ModerationLog } from '@/models/entities/ModerationLog.js'; import { UserEntityService } from './UserEntityService.js'; import { bindThis } from '@/decorators.js'; +import { Serialized } from 'schema-type'; +import { Packed } from 'misskey-js'; @Injectable() export class ModerationLogEntityService { @@ -20,7 +22,7 @@ export class ModerationLogEntityService { @bindThis public async pack( src: ModerationLog['id'] | ModerationLog, - ) { + ): Promise>> { const log = typeof src === 'object' ? src : await this.moderationLogsRepository.findOneByOrFail({ id: src }); return await awaitAll({ @@ -38,8 +40,7 @@ export class ModerationLogEntityService { @bindThis public packMany( reports: any[], - ) { + ): Promise>[]> { return Promise.all(reports.map(x => this.pack(x))); } } - diff --git a/packages/backend/src/server/api/endpoints/admin/show-moderation-logs.ts b/packages/backend/src/server/api/endpoints/admin/show-moderation-logs.ts index 24335a21c..879ec66db 100644 --- a/packages/backend/src/server/api/endpoints/admin/show-moderation-logs.ts +++ b/packages/backend/src/server/api/endpoints/admin/show-moderation-logs.ts @@ -5,65 +5,10 @@ import { QueryService } from '@/core/QueryService.js'; import { DI } from '@/di-symbols.js'; import { ModerationLogEntityService } from '@/core/entities/ModerationLogEntityService.js'; -export const meta = { - tags: ['admin'], - - requireCredential: true, - requireModerator: true, - - res: { - type: 'array', - optional: false, nullable: false, - items: { - type: 'object', - optional: false, nullable: false, - properties: { - id: { - type: 'string', - optional: false, nullable: false, - format: 'id', - }, - createdAt: { - type: 'string', - optional: false, nullable: false, - format: 'date-time', - }, - type: { - type: 'string', - optional: false, nullable: false, - }, - info: { - type: 'object', - optional: false, nullable: false, - }, - userId: { - type: 'string', - optional: false, nullable: false, - format: 'id', - }, - user: { - type: 'object', - optional: false, nullable: false, - ref: 'UserDetailed', - }, - }, - }, - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, - sinceId: { type: 'string', format: 'misskey:id' }, - untilId: { type: 'string', format: 'misskey:id' }, - }, - required: [], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/show-moderation-logs'> { + name = 'admin/show-moderation-logs' as const; constructor( @Inject(DI.moderationLogsRepository) private moderationLogsRepository: ModerationLogsRepository, @@ -71,7 +16,7 @@ export default class extends Endpoint { private moderationLogEntityService: ModerationLogEntityService, private queryService: QueryService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const query = this.queryService.makePaginationQuery(this.moderationLogsRepository.createQueryBuilder('report'), ps.sinceId, ps.untilId); const reports = await query.take(ps.limit).getMany(); diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index acfc0f179..fe0692733 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -1626,6 +1626,30 @@ export const endpoints = { } }], }, + 'admin/show-moderation-logs': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: { + type: 'object', + properties: { + limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, + sinceId: { type: 'string', format: 'misskey:id' }, + untilId: { type: 'string', format: 'misskey:id' }, + }, + required: [], + }, + res: { + type: 'array', + items: { + $ref: 'https://misskey-hub.net/api/schemas/ModerationLog', + }, + } + }], + }, } as const satisfies { [x: string]: IEndpointMeta; }; /** diff --git a/packages/misskey-js/src/schemas.ts b/packages/misskey-js/src/schemas.ts index e4df1b74f..b5c859063 100644 --- a/packages/misskey-js/src/schemas.ts +++ b/packages/misskey-js/src/schemas.ts @@ -51,6 +51,7 @@ import { ServerInfoSchema, ServerInfoAdminSchema, } from './schemas/server-info.js'; +import { packedModerationLogSchema } from './schemas/moderation-log.js'; import { Error, ApiError } from './schemas/error.js'; import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type'; @@ -101,6 +102,7 @@ export const refs = { InstanceMetaAdmin: InstanceMetaAdminSchema, ServerInfo: ServerInfoSchema, ServerInfoAdmin: ServerInfoAdminSchema, + ModerationLog: packedModerationLogSchema, Error: Error, ApiError: ApiError, diff --git a/packages/misskey-js/src/schemas/moderation-log.ts b/packages/misskey-js/src/schemas/moderation-log.ts new file mode 100644 index 000000000..6a1483e8f --- /dev/null +++ b/packages/misskey-js/src/schemas/moderation-log.ts @@ -0,0 +1,30 @@ +import type { JSONSchema7Definition } from 'schema-type'; + +export const packedModerationLogSchema = { + $id: 'https://misskey-hub.net/api/schemas/ModerationLog', + + type: 'object', + properties: { + id: { $ref: 'https://misskey-hub.net/api/schemas/Id' }, + createdAt: { + type: 'string', + format: 'date-time', + }, + type: { + type: 'string', + }, + info: { + type: 'object', + }, + userId: { $ref: 'https://misskey-hub.net/api/schemas/Id' }, + user: { $ref: 'https://misskey-hub.net/api/schemas/UserDetailed' }, + }, + required: [ + 'id', + 'createdAt', + 'type', + 'info', + 'userId', + 'user', + ], +} as const satisfies JSONSchema7Definition; diff --git a/packages/misskey-js/test-d/schemas.ts b/packages/misskey-js/test-d/schemas.ts index aa702d6d6..444f04a8a 100644 --- a/packages/misskey-js/test-d/schemas.ts +++ b/packages/misskey-js/test-d/schemas.ts @@ -119,6 +119,9 @@ describe('schemas', () => { type ServerInfo = Packed<'ServerInfo'>; type ServerInfoAdmin = Packed<'ServerInfoAdmin'>; }); + test('moderation log', () => { + type ModerationLog = Packed<'ModerationLog'>; + }); test('error', () => { type Error = Packed<'Error'>; type ApiError = Packed<'ApiError'>;