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) # Upload or download file size limits (bytes)
#maxFileSize: 262144000 #maxFileSize: 262144000
# Max note text length (in characters)
#maxNoteTextLength: 3000
#allowedPrivateNetworks: [ #allowedPrivateNetworks: [
# '127.0.0.1/32' # '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); config.port = config.port || parseInt(process.env.PORT || '', 10);
if (!config.maxNoteTextLength) config.maxNoteTextLength = 3000;
mixin.version = meta.version; mixin.version = meta.version;
mixin.host = url.host; mixin.host = url.host;
mixin.hostname = url.hostname; mixin.hostname = url.hostname;

View file

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

View file

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

View file

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

View file

@ -2,7 +2,6 @@ import { IsNull } from 'typeorm';
import config from '@/config/index.js'; import config from '@/config/index.js';
import { fetchMeta } from '@/misc/fetch-meta.js'; import { fetchMeta } from '@/misc/fetch-meta.js';
import { Emojis, Users } from '@/models/index.js'; import { Emojis, Users } from '@/models/index.js';
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import define from '../define.js'; import define from '../define.js';
export const meta = { export const meta = {
@ -311,7 +310,7 @@ export default define(meta, paramDef, async (ps, me) => {
iconUrl: instance.iconUrl, iconUrl: instance.iconUrl,
backgroundImageUrl: instance.backgroundImageUrl, backgroundImageUrl: instance.backgroundImageUrl,
logoImageUrl: instance.logoImageUrl, logoImageUrl: instance.logoImageUrl,
maxNoteTextLength: MAX_NOTE_TEXT_LENGTH, // 後方互換性のため maxNoteTextLength: config.maxNoteTextLength,
emojis: await Emojis.packMany(emojis), emojis: await Emojis.packMany(emojis),
defaultLightTheme: instance.defaultLightTheme, defaultLightTheme: instance.defaultLightTheme,
defaultDarkTheme: instance.defaultDarkTheme, 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 { DriveFile } from '@/models/entities/drive-file.js';
import { Note } from '@/models/entities/note.js'; import { Note } from '@/models/entities/note.js';
import { Channel } from '@/models/entities/channel.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 { isPureRenote } from '@/misc/renote.js';
import config from '@/config/index.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import define from '../../define.js'; import define from '../../define.js';
import { getNote } from '../../common/getters.js'; import { getNote } from '../../common/getters.js';
@ -99,7 +100,7 @@ export const paramDef = {
visibleUserIds: { type: 'array', uniqueItems: true, items: { visibleUserIds: { type: 'array', uniqueItems: true, items: {
type: 'string', format: 'misskey:id', 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 }, cw: { type: 'string', nullable: true, maxLength: 100 },
localOnly: { type: 'boolean', default: false }, localOnly: { type: 'boolean', default: false },
noExtractMentions: { 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 // (re)note with text, files and poll are optional
properties: { 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'], required: ['text'],
}, },

View file

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