投稿の最大文字数情報を設定ファイルではなくDBに保存するように
This commit is contained in:
		
							parent
							
								
									10c434f24a
								
							
						
					
					
						commit
						d7a3b71028
					
				
					 10 changed files with 37 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -59,6 +59,13 @@ export const meta = {
 | 
			
		|||
				'ja-JP': 'インスタンスの紹介文'
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		maxNoteTextLength: {
 | 
			
		||||
			validator: $.num.optional.min(1),
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '投稿の最大文字数'
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -93,6 +100,10 @@ export default define(meta, (ps) => new Promise(async (res, rej) => {
 | 
			
		|||
		set.description = ps.description;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (ps.maxNoteTextLength) {
 | 
			
		||||
		set.maxNoteTextLength = ps.maxNoteTextLength;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	await Meta.update({}, {
 | 
			
		||||
		$set: set
 | 
			
		||||
	}, { upsert: true });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -62,7 +62,7 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
 | 
			
		|||
		swPublickey: config.sw ? config.sw.public_key : null,
 | 
			
		||||
		hidedTags: (me && me.isAdmin) ? met.hidedTags : undefined,
 | 
			
		||||
		bannerUrl: met.bannerUrl,
 | 
			
		||||
		maxNoteTextLength: config.maxNoteTextLength,
 | 
			
		||||
		maxNoteTextLength: met.maxNoteTextLength || 1000,
 | 
			
		||||
 | 
			
		||||
		emojis: emojis,
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,10 +1,20 @@
 | 
			
		|||
import $ from 'cafy'; import ID, { transform, transformMany } from '../../../../misc/cafy-id';
 | 
			
		||||
const ms = require('ms');
 | 
			
		||||
import Note, { INote, isValidText, isValidCw, pack } from '../../../../models/note';
 | 
			
		||||
import { length } from 'stringz';
 | 
			
		||||
import Note, { INote, isValidCw, pack } from '../../../../models/note';
 | 
			
		||||
import User, { IUser } from '../../../../models/user';
 | 
			
		||||
import DriveFile, { IDriveFile } from '../../../../models/drive-file';
 | 
			
		||||
import create from '../../../../services/note/create';
 | 
			
		||||
import define from '../../define';
 | 
			
		||||
import Meta from '../../../../models/meta';
 | 
			
		||||
 | 
			
		||||
let maxNoteTextLength = 1000;
 | 
			
		||||
 | 
			
		||||
setInterval(() => {
 | 
			
		||||
	Meta.findOne({}).then(m => {
 | 
			
		||||
		if (m.maxNoteTextLength) maxNoteTextLength = m.maxNoteTextLength;
 | 
			
		||||
	});
 | 
			
		||||
}, 3000);
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
| 
						 | 
				
			
			@ -40,7 +50,9 @@ export const meta = {
 | 
			
		|||
		},
 | 
			
		||||
 | 
			
		||||
		text: {
 | 
			
		||||
			validator: $.str.optional.nullable.pipe(isValidText),
 | 
			
		||||
			validator: $.str.optional.nullable.pipe(text =>
 | 
			
		||||
				length(text.trim()) <= maxNoteTextLength && text.trim() != ''
 | 
			
		||||
			),
 | 
			
		||||
			default: null as any,
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '投稿内容'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue