AbuseUserReport の category を camelCase にする & notLike で通報されないようにする (MisskeyIO#298)

This commit is contained in:
riku6460
2023-12-28 17:48:16 +09:00
committed by GitHub
parent 6de9a8ccbf
commit 2e2970eafd
11 changed files with 121 additions and 45 deletions

View File

@@ -77,7 +77,7 @@ export const meta = {
category: {
type: 'string',
nullable: false, optional: false,
}
},
},
},
},

View File

@@ -48,7 +48,31 @@ export const paramDef = {
properties: {
userId: { type: 'string', format: 'misskey:id' },
comment: { type: 'string', minLength: 1, maxLength: 2048 },
category: { type: 'string', minLength: 1, maxLength: 20, default: 'other' },
category: {
type: 'string',
default: 'other',
enum: [
'nsfw',
'spam',
'explicit',
'phishing',
'personalInfoLeak',
'selfHarm',
'criticalBreach',
'otherBreach',
'violationRights',
'violationRightsOther',
'other',
// for compatibility
'personalinfoleak',
'selfharm',
'criticalbreach',
'otherbreach',
'violationrights',
'violationrightsother',
'notlike',
],
},
},
required: ['userId', 'comment'],
} as const;
@@ -79,6 +103,20 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.cannotReportAdmin);
}
// for compatibility
if (ps.category === 'notlike') {
return;
}
const categoriesMap: Record<string, typeof paramDef['properties']['category']['enum'][number]> = {
'personalinfoleak': 'personalInfoLeak',
'selfharm': 'selfHarm',
'criticalbreach': 'criticalBreach',
'otherbreach': 'otherBreach',
'violationrights': 'violationRights',
'violationrightsother': 'violationRightsOther',
};
const report = await this.abuseUserReportsRepository.insert({
id: this.idService.gen(),
targetUserId: user.id,
@@ -86,7 +124,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
reporterId: me.id,
reporterHost: null,
comment: ps.comment,
category: ps.category,
category: typeof categoriesMap[ps.category] === 'string' ? categoriesMap[ps.category] : ps.category,
}).then(x => this.abuseUserReportsRepository.findOneByOrFail(x.identifiers[0]));
this.queueService.createReportAbuseJob(report);