wip
This commit is contained in:
parent
9ce6f99cad
commit
93ea327660
6 changed files with 92 additions and 86 deletions
|
@ -5,6 +5,8 @@ import { awaitAll } from '@/misc/prelude/await-all.js';
|
|||
import type { AbuseUserReport } from '@/models/entities/AbuseUserReport.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { Packed } from 'misskey-js';
|
||||
import { Serialized } from 'schema-type';
|
||||
|
||||
@Injectable()
|
||||
export class AbuseUserReportEntityService {
|
||||
|
@ -19,7 +21,7 @@ export class AbuseUserReportEntityService {
|
|||
@bindThis
|
||||
public async pack(
|
||||
src: AbuseUserReport['id'] | AbuseUserReport,
|
||||
) {
|
||||
): Promise<Serialized<Packed<'AbuseUserReport'>>> {
|
||||
const report = typeof src === 'object' ? src : await this.abuseUserReportsRepository.findOneByOrFail({ id: src });
|
||||
|
||||
return await awaitAll({
|
||||
|
@ -46,7 +48,7 @@ export class AbuseUserReportEntityService {
|
|||
@bindThis
|
||||
public packMany(
|
||||
reports: any[],
|
||||
) {
|
||||
): Promise<Serialized<Packed<'AbuseUserReport'>>[]> {
|
||||
return Promise.all(reports.map(x => this.pack(x)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,91 +5,10 @@ import { QueryService } from '@/core/QueryService.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { AbuseUserReportEntityService } from '@/core/entities/AbuseUserReportEntityService.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',
|
||||
nullable: false, optional: false,
|
||||
format: 'id',
|
||||
example: 'xxxxxxxxxx',
|
||||
},
|
||||
createdAt: {
|
||||
type: 'string',
|
||||
nullable: false, optional: false,
|
||||
format: 'date-time',
|
||||
},
|
||||
comment: {
|
||||
type: 'string',
|
||||
nullable: false, optional: false,
|
||||
},
|
||||
resolved: {
|
||||
type: 'boolean',
|
||||
nullable: false, optional: false,
|
||||
example: false,
|
||||
},
|
||||
reporterId: {
|
||||
type: 'string',
|
||||
nullable: false, optional: false,
|
||||
format: 'id',
|
||||
},
|
||||
targetUserId: {
|
||||
type: 'string',
|
||||
nullable: false, optional: false,
|
||||
format: 'id',
|
||||
},
|
||||
assigneeId: {
|
||||
type: 'string',
|
||||
nullable: true, optional: false,
|
||||
format: 'id',
|
||||
},
|
||||
reporter: {
|
||||
type: 'object',
|
||||
nullable: false, optional: false,
|
||||
ref: 'User',
|
||||
},
|
||||
targetUser: {
|
||||
type: 'object',
|
||||
nullable: false, optional: false,
|
||||
ref: 'User',
|
||||
},
|
||||
assignee: {
|
||||
type: 'object',
|
||||
nullable: true, optional: true,
|
||||
ref: 'User',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} 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' },
|
||||
state: { type: 'string', nullable: true, default: null },
|
||||
reporterOrigin: { type: 'string', enum: ['combined', 'local', 'remote'], default: 'combined' },
|
||||
targetUserOrigin: { type: 'string', enum: ['combined', 'local', 'remote'], default: 'combined' },
|
||||
forwarded: { type: 'boolean', default: false },
|
||||
},
|
||||
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/abuse-user-reports'> {
|
||||
name = 'admin/abuse-user-reports' as const;
|
||||
constructor(
|
||||
@Inject(DI.abuseUserReportsRepository)
|
||||
private abuseUserReportsRepository: AbuseUserReportsRepository,
|
||||
|
@ -97,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
private abuseUserReportEntityService: AbuseUserReportEntityService,
|
||||
private queryService: QueryService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(async (ps, me) => {
|
||||
const query = this.queryService.makePaginationQuery(this.abuseUserReportsRepository.createQueryBuilder('report'), ps.sinceId, ps.untilId);
|
||||
|
||||
switch (ps.state) {
|
||||
|
|
|
@ -1378,6 +1378,34 @@ export const endpoints = {
|
|||
}
|
||||
}],
|
||||
},
|
||||
'admin/abuse-user-reports': {
|
||||
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' },
|
||||
state: { type: ['string', 'null'], default: null },
|
||||
reporterOrigin: { type: 'string', enum: ['combined', 'local', 'remote'], default: 'combined' },
|
||||
targetUserOrigin: { type: 'string', enum: ['combined', 'local', 'remote'], default: 'combined' },
|
||||
forwarded: { type: 'boolean', default: false },
|
||||
},
|
||||
required: [],
|
||||
},
|
||||
res: {
|
||||
type: 'array',
|
||||
items: {
|
||||
$ref: 'https://misskey-hub.net/api/schemas/AbuseUserReport',
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
} as const satisfies { [x: string]: IEndpointMeta; };
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,6 +36,7 @@ import { packedFlashSchema } from './schemas/flash.js';
|
|||
import { packedAdSchema } from './schemas/ad.js';
|
||||
import { packedAnnouncementSchema } from './schemas/announcement.js';
|
||||
import { packedRelaySchema } from './schemas/relay.js';
|
||||
import { packedAbuseUserReportSchema } from './schemas/abuse-user-report.js';
|
||||
import {
|
||||
packedRoleSchema,
|
||||
packedRoleAssignSchema,
|
||||
|
@ -87,6 +88,7 @@ export const refs = {
|
|||
RoleAssign: packedRoleAssignSchema,
|
||||
RolePolicy: packedRolePolicySchema,
|
||||
RoleCondFormula: packedRoleCondFormulaSchema,
|
||||
AbuseUserReport: packedAbuseUserReportSchema,
|
||||
|
||||
Error: Error,
|
||||
ApiError: ApiError,
|
||||
|
|
52
packages/misskey-js/src/schemas/abuse-user-report.ts
Normal file
52
packages/misskey-js/src/schemas/abuse-user-report.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import type { JSONSchema7Definition } from 'schema-type';
|
||||
|
||||
export const packedAbuseUserReportSchema = {
|
||||
$id: 'https://misskey-hub.net/api/schemas/AbuseUserReport',
|
||||
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
|
||||
createdAt: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
},
|
||||
comment: {
|
||||
type: 'string',
|
||||
},
|
||||
resolved: {
|
||||
type: 'boolean',
|
||||
examples: [false],
|
||||
},
|
||||
reporterId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
|
||||
reporter: { $ref: 'https://misskey-hub.net/api/schemas/UserDetailed' },
|
||||
targetUserId: { $ref: 'https://misskey-hub.net/api/schemas/Id' },
|
||||
targetUser: { $ref: 'https://misskey-hub.net/api/schemas/UserDetailed' },
|
||||
assigneeId: {
|
||||
oneOf: [
|
||||
{ $ref: 'https://misskey-hub.net/api/schemas/Id' },
|
||||
{ type: 'null' },
|
||||
]
|
||||
},
|
||||
assignee: {
|
||||
oneOf: [
|
||||
{ $ref: 'https://misskey-hub.net/api/schemas/UserDetailed' },
|
||||
{ type: 'null' },
|
||||
]
|
||||
},
|
||||
forwarded: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'createdAt',
|
||||
'comment',
|
||||
'resolved',
|
||||
'reporterId',
|
||||
'reporter',
|
||||
'targetUserId',
|
||||
'targetUser',
|
||||
'assigneeId',
|
||||
'forwarded',
|
||||
],
|
||||
} as const satisfies JSONSchema7Definition;
|
|
@ -107,6 +107,9 @@ describe('schemas', () => {
|
|||
type RolePolicy = Packed<'RolePolicy'>;
|
||||
type RoleCondFormula = Packed<'RoleCondFormula'>;
|
||||
});
|
||||
test('abuse user report', () => {
|
||||
type AbuseUserReport = Packed<'AbuseUserReport'>;
|
||||
});
|
||||
test('error', () => {
|
||||
type Error = Packed<'Error'>;
|
||||
type ApiError = Packed<'ApiError'>;
|
||||
|
|
Loading…
Reference in a new issue