From 93ea327660238c2836cbba610e9ee878386ec609 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 29 May 2023 13:28:31 +0000 Subject: [PATCH] wip --- .../entities/AbuseUserReportEntityService.ts | 6 +- .../api/endpoints/admin/abuse-user-reports.ts | 87 +------------------ packages/misskey-js/src/endpoints.ts | 28 ++++++ packages/misskey-js/src/schemas.ts | 2 + .../src/schemas/abuse-user-report.ts | 52 +++++++++++ packages/misskey-js/test-d/schemas.ts | 3 + 6 files changed, 92 insertions(+), 86 deletions(-) create mode 100644 packages/misskey-js/src/schemas/abuse-user-report.ts diff --git a/packages/backend/src/core/entities/AbuseUserReportEntityService.ts b/packages/backend/src/core/entities/AbuseUserReportEntityService.ts index 7f8240b8b2..163d612f47 100644 --- a/packages/backend/src/core/entities/AbuseUserReportEntityService.ts +++ b/packages/backend/src/core/entities/AbuseUserReportEntityService.ts @@ -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>> { 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>[]> { return Promise.all(reports.map(x => this.pack(x))); } } diff --git a/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts b/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts index 9bba16166f..ffa014ff62 100644 --- a/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts +++ b/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts @@ -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 { +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 { 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) { diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index 7ee8706e3a..a199299299 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -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; }; /** diff --git a/packages/misskey-js/src/schemas.ts b/packages/misskey-js/src/schemas.ts index f284ce59f5..87f720a7aa 100644 --- a/packages/misskey-js/src/schemas.ts +++ b/packages/misskey-js/src/schemas.ts @@ -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, diff --git a/packages/misskey-js/src/schemas/abuse-user-report.ts b/packages/misskey-js/src/schemas/abuse-user-report.ts new file mode 100644 index 0000000000..bd86ea47b3 --- /dev/null +++ b/packages/misskey-js/src/schemas/abuse-user-report.ts @@ -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; diff --git a/packages/misskey-js/test-d/schemas.ts b/packages/misskey-js/test-d/schemas.ts index 658d57caff..43f1cda765 100644 --- a/packages/misskey-js/test-d/schemas.ts +++ b/packages/misskey-js/test-d/schemas.ts @@ -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'>;