1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-11-27 14:28:49 +09:00

投稿の最大文字数情報を設定ファイルではなくDBに保存するように

This commit is contained in:
syuilo 2018-11-05 11:09:05 +09:00
parent 10c434f24a
commit d7a3b71028
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
10 changed files with 37 additions and 16 deletions

View File

@ -167,6 +167,3 @@ drive:
# external: true
# engine: http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-misskey-api.cgi?{{host}}+{{user}}+{{limit}}+{{offset}}
# timeout: 300000
# Max allowed note text length in charactors
maxNoteTextLength: 1000

View File

@ -1077,6 +1077,7 @@ admin/views/instance.vue:
instance-name: "インスタンス名"
instance-description: "インスタンスの紹介"
banner-url: "バナー画像URL"
max-note-text-length: "投稿の最大文字数"
disableRegistration: "ユーザー登録の受付を停止する"
disableLocalTimeline: "ローカルタイムラインを無効にする"
invite: "招待"

View File

@ -6,6 +6,7 @@
<ui-input v-model="name">%i18n:@instance-name%</ui-input>
<ui-textarea v-model="description">%i18n:@instance-description%</ui-textarea>
<ui-input v-model="bannerUrl">%i18n:@banner-url%</ui-input>
<ui-input v-model="maxNoteTextLength">%i18n:@max-note-text-length%</ui-input>
<ui-button @click="updateMeta">%i18n:@save%</ui-button>
</section>
</ui-card>
@ -39,6 +40,7 @@ export default Vue.extend({
bannerUrl: null,
name: null,
description: null,
maxNoteTextLength: null,
inviteCode: null,
};
},
@ -48,6 +50,7 @@ export default Vue.extend({
this.bannerUrl = meta.bannerUrl;
this.name = meta.name;
this.description = meta.description;
this.maxNoteTextLength = meta.maxNoteTextLength;
});
},
@ -69,7 +72,8 @@ export default Vue.extend({
disableLocalTimeline: this.disableLocalTimeline,
bannerUrl: this.bannerUrl,
name: this.name,
description: this.description
description: this.description,
maxNoteTextLength: parseInt(this.maxNoteTextLength, 10)
}).then(() => {
this.$swal({
type: 'success',

View File

@ -49,8 +49,6 @@ export default function load() {
if (config.localDriveCapacityMb == null) config.localDriveCapacityMb = 256;
if (config.remoteDriveCapacityMb == null) config.remoteDriveCapacityMb = 8;
if (config.maxNoteTextLength == null) config.maxNoteTextLength = 1000;
return Object.assign(config, mixin);
}

View File

@ -107,8 +107,6 @@ export type Source = {
engine: string;
timeout: number;
};
maxNoteTextLength?: number;
};
/**

View File

@ -43,4 +43,9 @@ export type IMeta = {
disableLocalTimeline?: boolean;
hidedTags?: string[];
bannerUrl?: string;
/**
* Max allowed note text length in charactors
*/
maxNoteTextLength?: number;
};

View File

@ -11,7 +11,6 @@ import Reaction from './note-reaction';
import { packMany as packFileMany, IDriveFile } from './drive-file';
import Favorite from './favorite';
import Following from './following';
import config from '../config';
import Emoji from './emoji';
const Note = db.get<INote>('notes');
@ -27,10 +26,6 @@ Note.createIndex({ createdAt: -1 });
Note.createIndex({ score: -1 }, { sparse: true });
export default Note;
export function isValidText(text: string): boolean {
return length(text.trim()) <= config.maxNoteTextLength && text.trim() != '';
}
export function isValidCw(text: string): boolean {
return length(text.trim()) <= 100;
}

View File

@ -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 });

View File

@ -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,

View File

@ -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': '投稿内容'