Apply DB limit to the maximum note text length (#5465)
This commit is contained in:
parent
cea2d621f2
commit
6ba5968861
|
@ -0,0 +1,8 @@
|
|||
|
||||
// If you change DB_* values, you must also change the DB schema.
|
||||
|
||||
/**
|
||||
* Maximum note text length that can be stored in DB.
|
||||
* Surrogate pairs count as one
|
||||
*/
|
||||
export const DB_MAX_NOTE_TEXT_LENGTH = 8192;
|
|
@ -3,6 +3,7 @@ import define from '../../define';
|
|||
import { getConnection } from 'typeorm';
|
||||
import { Meta } from '../../../../models/entities/meta';
|
||||
import { insertModerationLog } from '../../../../services/insert-moderation-log';
|
||||
import { DB_MAX_NOTE_TEXT_LENGTH } from '../../../../misc/hard-limits';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
|
@ -121,7 +122,7 @@ export const meta = {
|
|||
},
|
||||
|
||||
maxNoteTextLength: {
|
||||
validator: $.optional.num.min(0),
|
||||
validator: $.optional.num.min(0).max(DB_MAX_NOTE_TEXT_LENGTH),
|
||||
desc: {
|
||||
'ja-JP': '投稿の最大文字数'
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import * as pkg from '../../../../package.json';
|
|||
import { Emojis } from '../../../models';
|
||||
import { getConnection } from 'typeorm';
|
||||
import redis from '../../../db/redis';
|
||||
import { DB_MAX_NOTE_TEXT_LENGTH } from '../../../misc/hard-limits';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
|
@ -138,7 +139,7 @@ export default define(meta, async (ps, me) => {
|
|||
bannerUrl: instance.bannerUrl,
|
||||
errorImageUrl: instance.errorImageUrl,
|
||||
iconUrl: instance.iconUrl,
|
||||
maxNoteTextLength: instance.maxNoteTextLength,
|
||||
maxNoteTextLength: Math.min(instance.maxNoteTextLength, DB_MAX_NOTE_TEXT_LENGTH),
|
||||
emojis: emojis.map(e => ({
|
||||
id: e.id,
|
||||
aliases: e.aliases,
|
||||
|
|
|
@ -10,6 +10,7 @@ import { User } from '../../../../models/entities/user';
|
|||
import { Users, DriveFiles, Notes } from '../../../../models';
|
||||
import { DriveFile } from '../../../../models/entities/drive-file';
|
||||
import { Note } from '../../../../models/entities/note';
|
||||
import { DB_MAX_NOTE_TEXT_LENGTH } from '../../../../misc/hard-limits';
|
||||
|
||||
let maxNoteTextLength = 1000;
|
||||
|
||||
|
@ -55,7 +56,9 @@ export const meta = {
|
|||
|
||||
text: {
|
||||
validator: $.optional.nullable.str.pipe(text =>
|
||||
length(text.trim()) <= maxNoteTextLength && text.trim() != ''
|
||||
text.trim() != ''
|
||||
&& length(text.trim()) <= maxNoteTextLength
|
||||
&& Array.from(text.trim()).length <= DB_MAX_NOTE_TEXT_LENGTH // DB limit
|
||||
),
|
||||
default: null as any,
|
||||
desc: {
|
||||
|
|
Loading…
Reference in New Issue