This commit is contained in:
tamaina 2023-05-29 16:39:03 +00:00
parent dbeb1856ac
commit 68a2aa3efd
6 changed files with 66 additions and 61 deletions

View file

@ -6,6 +6,8 @@ import type { } from '@/models/entities/Blocking.js';
import type { ModerationLog } from '@/models/entities/ModerationLog.js'; import type { ModerationLog } from '@/models/entities/ModerationLog.js';
import { UserEntityService } from './UserEntityService.js'; import { UserEntityService } from './UserEntityService.js';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import { Serialized } from 'schema-type';
import { Packed } from 'misskey-js';
@Injectable() @Injectable()
export class ModerationLogEntityService { export class ModerationLogEntityService {
@ -20,7 +22,7 @@ export class ModerationLogEntityService {
@bindThis @bindThis
public async pack( public async pack(
src: ModerationLog['id'] | ModerationLog, src: ModerationLog['id'] | ModerationLog,
) { ): Promise<Serialized<Packed<'ModerationLog'>>> {
const log = typeof src === 'object' ? src : await this.moderationLogsRepository.findOneByOrFail({ id: src }); const log = typeof src === 'object' ? src : await this.moderationLogsRepository.findOneByOrFail({ id: src });
return await awaitAll({ return await awaitAll({
@ -38,8 +40,7 @@ export class ModerationLogEntityService {
@bindThis @bindThis
public packMany( public packMany(
reports: any[], reports: any[],
) { ): Promise<Serialized<Packed<'ModerationLog'>>[]> {
return Promise.all(reports.map(x => this.pack(x))); return Promise.all(reports.map(x => this.pack(x)));
} }
} }

View file

@ -5,65 +5,10 @@ import { QueryService } from '@/core/QueryService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { ModerationLogEntityService } from '@/core/entities/ModerationLogEntityService.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 // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'admin/show-moderation-logs'> {
name = 'admin/show-moderation-logs' as const;
constructor( constructor(
@Inject(DI.moderationLogsRepository) @Inject(DI.moderationLogsRepository)
private moderationLogsRepository: ModerationLogsRepository, private moderationLogsRepository: ModerationLogsRepository,
@ -71,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private moderationLogEntityService: ModerationLogEntityService, private moderationLogEntityService: ModerationLogEntityService,
private queryService: QueryService, 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 query = this.queryService.makePaginationQuery(this.moderationLogsRepository.createQueryBuilder('report'), ps.sinceId, ps.untilId);
const reports = await query.take(ps.limit).getMany(); const reports = await query.take(ps.limit).getMany();

View file

@ -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; }; } as const satisfies { [x: string]: IEndpointMeta; };
/** /**

View file

@ -51,6 +51,7 @@ import {
ServerInfoSchema, ServerInfoSchema,
ServerInfoAdminSchema, ServerInfoAdminSchema,
} from './schemas/server-info.js'; } from './schemas/server-info.js';
import { packedModerationLogSchema } from './schemas/moderation-log.js';
import { Error, ApiError } from './schemas/error.js'; import { Error, ApiError } from './schemas/error.js';
import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type'; import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type';
@ -101,6 +102,7 @@ export const refs = {
InstanceMetaAdmin: InstanceMetaAdminSchema, InstanceMetaAdmin: InstanceMetaAdminSchema,
ServerInfo: ServerInfoSchema, ServerInfo: ServerInfoSchema,
ServerInfoAdmin: ServerInfoAdminSchema, ServerInfoAdmin: ServerInfoAdminSchema,
ModerationLog: packedModerationLogSchema,
Error: Error, Error: Error,
ApiError: ApiError, ApiError: ApiError,

View file

@ -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;

View file

@ -119,6 +119,9 @@ describe('schemas', () => {
type ServerInfo = Packed<'ServerInfo'>; type ServerInfo = Packed<'ServerInfo'>;
type ServerInfoAdmin = Packed<'ServerInfoAdmin'>; type ServerInfoAdmin = Packed<'ServerInfoAdmin'>;
}); });
test('moderation log', () => {
type ModerationLog = Packed<'ModerationLog'>;
});
test('error', () => { test('error', () => {
type Error = Packed<'Error'>; type Error = Packed<'Error'>;
type ApiError = Packed<'ApiError'>; type ApiError = Packed<'ApiError'>;