add separate limits for CW length

This commit is contained in:
Hazelnoot 2024-10-26 10:04:23 -04:00
parent 10d3d9f382
commit 01e98c75ab
10 changed files with 91 additions and 9 deletions

View file

@ -90,6 +90,12 @@ export const meta = {
id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16',
},
maxCwLength: {
message: 'You tried posting a content warning which is too long.',
code: 'MAX_CW_LENGTH',
id: '7004c478-bda3-4b4f-acb2-4316398c9d52',
},
cannotReplyToSpecifiedVisibilityNoteWithExtendedVisibility: {
message: 'You cannot reply to a specified visibility note with extended visibility.',
code: 'CANNOT_REPLY_TO_SPECIFIED_VISIBILITY_NOTE_WITH_EXTENDED_VISIBILITY',
@ -250,10 +256,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private noteCreateService: NoteCreateService,
) {
super(meta, paramDef, async (ps, me) => {
const contentLength = (ps.text?.length ?? 0) + (ps.cw?.length ?? 0);
if (contentLength > this.config.maxNoteLength) {
if (ps.text && ps.text.length > this.config.maxNoteLength) {
throw new ApiError(meta.errors.maxLength);
}
if (ps.cw && ps.cw.length > this.config.maxCwLength) {
throw new ApiError(meta.errors.maxCwLength);
}
let visibleUsers: MiUser[] = [];
if (ps.visibleUserIds) {