backend: make max note length configurable (#210)

Changelog: Added
Closes: FoundKeyGang/FoundKey#208
Co-authored-by: Francis Dinh <normandy@biribiri.dev>
Reviewed-on: FoundKeyGang/FoundKey#210
This commit is contained in:
Norm 2022-10-18 17:33:00 +00:00
parent 3aa1d3bf97
commit 7257338077
8 changed files with 14 additions and 11 deletions

View file

@ -124,6 +124,9 @@ redis:
# Upload or download file size limits (bytes)
#maxFileSize: 262144000
# Max note text length (in characters)
#maxNoteTextLength: 3000
#allowedPrivateNetworks: [
# '127.0.0.1/32'
#]

View file

@ -38,6 +38,8 @@ export default function load(): Config {
config.port = config.port || parseInt(process.env.PORT || '', 10);
if (!config.maxNoteTextLength) config.maxNoteTextLength = 3000;
mixin.version = meta.version;
mixin.host = url.host;
mixin.hostname = url.hostname;

View file

@ -41,6 +41,8 @@ export type Source = {
maxFileSize?: number;
maxNoteTextLength?: number;
accesslog?: string;
clusterLimit?: number;

View file

@ -1,5 +1,3 @@
export const MAX_NOTE_TEXT_LENGTH = 3000;
// Time constants
export const SECOND = 1000;
export const MINUTE = 60 * SECOND;

View file

@ -1,6 +1,5 @@
import config from '@/config/index.js';
import { fetchMeta } from '@/misc/fetch-meta.js';
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import define from '../../define.js';
export const meta = {
@ -310,7 +309,7 @@ export default define(meta, paramDef, async (ps, me) => {
iconUrl: instance.iconUrl,
backgroundImageUrl: instance.backgroundImageUrl,
logoImageUrl: instance.logoImageUrl,
maxNoteTextLength: MAX_NOTE_TEXT_LENGTH, // 後方互換性のため
maxNoteTextLength: config.maxNoteTextLength,
defaultLightTheme: instance.defaultLightTheme,
defaultDarkTheme: instance.defaultDarkTheme,
enableEmail: instance.enableEmail,

View file

@ -2,7 +2,6 @@ import { IsNull } from 'typeorm';
import config from '@/config/index.js';
import { fetchMeta } from '@/misc/fetch-meta.js';
import { Emojis, Users } from '@/models/index.js';
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import define from '../define.js';
export const meta = {
@ -311,7 +310,7 @@ export default define(meta, paramDef, async (ps, me) => {
iconUrl: instance.iconUrl,
backgroundImageUrl: instance.backgroundImageUrl,
logoImageUrl: instance.logoImageUrl,
maxNoteTextLength: MAX_NOTE_TEXT_LENGTH, // 後方互換性のため
maxNoteTextLength: config.maxNoteTextLength,
emojis: await Emojis.packMany(emojis),
defaultLightTheme: instance.defaultLightTheme,
defaultDarkTheme: instance.defaultDarkTheme,

View file

@ -6,8 +6,9 @@ import { Users, DriveFiles, Notes, Channels, Blockings } from '@/models/index.js
import { DriveFile } from '@/models/entities/drive-file.js';
import { Note } from '@/models/entities/note.js';
import { Channel } from '@/models/entities/channel.js';
import { MAX_NOTE_TEXT_LENGTH, HOUR } from '@/const.js';
import { HOUR } from '@/const.js';
import { isPureRenote } from '@/misc/renote.js';
import config from '@/config/index.js';
import { ApiError } from '../../error.js';
import define from '../../define.js';
import { getNote } from '../../common/getters.js';
@ -99,7 +100,7 @@ export const paramDef = {
visibleUserIds: { type: 'array', uniqueItems: true, items: {
type: 'string', format: 'misskey:id',
} },
text: { type: 'string', maxLength: MAX_NOTE_TEXT_LENGTH, nullable: true },
text: { type: 'string', maxLength: config.maxNoteTextLength, nullable: true },
cw: { type: 'string', nullable: true, maxLength: 100 },
localOnly: { type: 'boolean', default: false },
noExtractMentions: { type: 'boolean', default: false },
@ -146,7 +147,7 @@ export const paramDef = {
{
// (re)note with text, files and poll are optional
properties: {
text: { type: 'string', minLength: 1, maxLength: MAX_NOTE_TEXT_LENGTH, nullable: false },
text: { type: 'string', minLength: 1, maxLength: config.maxNoteTextLength, nullable: false },
},
required: ['text'],
},

View file

@ -3,7 +3,6 @@ import { IsNull, MoreThan } from 'typeorm';
import config from '@/config/index.js';
import { fetchMeta } from '@/misc/fetch-meta.js';
import { Users, Notes } from '@/models/index.js';
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import { Cache } from '@/misc/cache.js';
const router = new Router();
@ -71,7 +70,7 @@ const nodeinfo2 = async () => {
emailRequiredForSignup: meta.emailRequiredForSignup,
enableHcaptcha: meta.enableHcaptcha,
enableRecaptcha: meta.enableRecaptcha,
maxNoteTextLength: MAX_NOTE_TEXT_LENGTH,
maxNoteTextLength: config.maxNoteTextLength,
enableTwitterIntegration: meta.enableTwitterIntegration,
enableGithubIntegration: meta.enableGithubIntegration,
enableDiscordIntegration: meta.enableDiscordIntegration,