diff --git a/packages/backend/src/core/entities/ModerationLogEntityService.ts b/packages/backend/src/core/entities/ModerationLogEntityService.ts index 7058e38af9..c4ce5aa758 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 24335a21cc..879ec66db7 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 acfc0f1796..fe0692733a 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 e4df1b74fd..b5c8590633 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 0000000000..6a1483e8f4 --- /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 aa702d6d61..444f04a8ab 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'>;