fix length validation
This commit is contained in:
parent
063b2ff266
commit
3842a1ee8c
|
@ -346,6 +346,18 @@ export class NoteCreateService implements OnApplicationShutdown {
|
||||||
data.text = null;
|
data.text = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.cw) {
|
||||||
|
if (data.cw.length > DB_MAX_NOTE_TEXT_LENGTH) {
|
||||||
|
data.cw = data.cw.slice(0, DB_MAX_NOTE_TEXT_LENGTH);
|
||||||
|
}
|
||||||
|
data.cw = data.cw.trim();
|
||||||
|
if (data.cw === '') {
|
||||||
|
data.cw = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data.cw = null;
|
||||||
|
}
|
||||||
|
|
||||||
let tags = data.apHashtags;
|
let tags = data.apHashtags;
|
||||||
let emojis = data.apEmojis;
|
let emojis = data.apEmojis;
|
||||||
let mentionedUsers = data.apMentions;
|
let mentionedUsers = data.apMentions;
|
||||||
|
|
|
@ -371,6 +371,18 @@ export class NoteEditService implements OnApplicationShutdown {
|
||||||
data.text = null;
|
data.text = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.cw) {
|
||||||
|
if (data.cw.length > DB_MAX_NOTE_TEXT_LENGTH) {
|
||||||
|
data.cw = data.cw.slice(0, DB_MAX_NOTE_TEXT_LENGTH);
|
||||||
|
}
|
||||||
|
data.cw = data.cw.trim();
|
||||||
|
if (data.cw === '') {
|
||||||
|
data.cw = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data.cw = null;
|
||||||
|
}
|
||||||
|
|
||||||
let tags = data.apHashtags;
|
let tags = data.apHashtags;
|
||||||
let emojis = data.apEmojis;
|
let emojis = data.apEmojis;
|
||||||
let mentionedUsers = data.apMentions;
|
let mentionedUsers = data.apMentions;
|
||||||
|
|
|
@ -252,7 +252,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
private noteCreateService: NoteCreateService,
|
private noteCreateService: NoteCreateService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
if (ps.text && (ps.text.length > this.config.maxNoteLength)) {
|
const contentLength = (ps.text?.length ?? 0) + (ps.cw?.length ?? 0);
|
||||||
|
if (contentLength > this.config.maxNoteLength) {
|
||||||
throw new ApiError(meta.errors.maxLength);
|
throw new ApiError(meta.errors.maxLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -297,9 +297,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
private noteEditService: NoteEditService,
|
private noteEditService: NoteEditService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
if (ps.text && (ps.text.length > this.config.maxNoteLength)) {
|
const contentLength = (ps.text?.length ?? 0) + (ps.cw?.length ?? 0);
|
||||||
|
if (contentLength > this.config.maxNoteLength) {
|
||||||
throw new ApiError(meta.errors.maxLength);
|
throw new ApiError(meta.errors.maxLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
let visibleUsers: MiUser[] = [];
|
let visibleUsers: MiUser[] = [];
|
||||||
if (ps.visibleUserIds) {
|
if (ps.visibleUserIds) {
|
||||||
visibleUsers = await this.usersRepository.findBy({
|
visibleUsers = await this.usersRepository.findBy({
|
||||||
|
|
Loading…
Reference in New Issue