wip
This commit is contained in:
parent
dbeb1856ac
commit
68a2aa3efd
|
@ -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<Serialized<Packed<'ModerationLog'>>> {
|
||||
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<Serialized<Packed<'ModerationLog'>>[]> {
|
||||
return Promise.all(reports.map(x => this.pack(x)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<typeof meta, typeof paramDef> {
|
||||
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<typeof meta, typeof paramDef> {
|
|||
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();
|
||||
|
|
|
@ -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; };
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
|
@ -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'>;
|
||||
|
|
Loading…
Reference in New Issue