mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 14:05:14 +00:00
投稿の最大文字数情報を設定ファイルではなくDBに保存するように
This commit is contained in:
parent
10c434f24a
commit
d7a3b71028
10 changed files with 37 additions and 16 deletions
|
@ -167,6 +167,3 @@ drive:
|
||||||
# external: true
|
# external: true
|
||||||
# engine: http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-misskey-api.cgi?{{host}}+{{user}}+{{limit}}+{{offset}}
|
# engine: http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-misskey-api.cgi?{{host}}+{{user}}+{{limit}}+{{offset}}
|
||||||
# timeout: 300000
|
# timeout: 300000
|
||||||
|
|
||||||
# Max allowed note text length in charactors
|
|
||||||
maxNoteTextLength: 1000
|
|
||||||
|
|
|
@ -1077,6 +1077,7 @@ admin/views/instance.vue:
|
||||||
instance-name: "インスタンス名"
|
instance-name: "インスタンス名"
|
||||||
instance-description: "インスタンスの紹介"
|
instance-description: "インスタンスの紹介"
|
||||||
banner-url: "バナー画像URL"
|
banner-url: "バナー画像URL"
|
||||||
|
max-note-text-length: "投稿の最大文字数"
|
||||||
disableRegistration: "ユーザー登録の受付を停止する"
|
disableRegistration: "ユーザー登録の受付を停止する"
|
||||||
disableLocalTimeline: "ローカルタイムラインを無効にする"
|
disableLocalTimeline: "ローカルタイムラインを無効にする"
|
||||||
invite: "招待"
|
invite: "招待"
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
<ui-input v-model="name">%i18n:@instance-name%</ui-input>
|
<ui-input v-model="name">%i18n:@instance-name%</ui-input>
|
||||||
<ui-textarea v-model="description">%i18n:@instance-description%</ui-textarea>
|
<ui-textarea v-model="description">%i18n:@instance-description%</ui-textarea>
|
||||||
<ui-input v-model="bannerUrl">%i18n:@banner-url%</ui-input>
|
<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>
|
<ui-button @click="updateMeta">%i18n:@save%</ui-button>
|
||||||
</section>
|
</section>
|
||||||
</ui-card>
|
</ui-card>
|
||||||
|
@ -39,6 +40,7 @@ export default Vue.extend({
|
||||||
bannerUrl: null,
|
bannerUrl: null,
|
||||||
name: null,
|
name: null,
|
||||||
description: null,
|
description: null,
|
||||||
|
maxNoteTextLength: null,
|
||||||
inviteCode: null,
|
inviteCode: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -48,6 +50,7 @@ export default Vue.extend({
|
||||||
this.bannerUrl = meta.bannerUrl;
|
this.bannerUrl = meta.bannerUrl;
|
||||||
this.name = meta.name;
|
this.name = meta.name;
|
||||||
this.description = meta.description;
|
this.description = meta.description;
|
||||||
|
this.maxNoteTextLength = meta.maxNoteTextLength;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -69,7 +72,8 @@ export default Vue.extend({
|
||||||
disableLocalTimeline: this.disableLocalTimeline,
|
disableLocalTimeline: this.disableLocalTimeline,
|
||||||
bannerUrl: this.bannerUrl,
|
bannerUrl: this.bannerUrl,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
description: this.description
|
description: this.description,
|
||||||
|
maxNoteTextLength: parseInt(this.maxNoteTextLength, 10)
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.$swal({
|
this.$swal({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
|
|
|
@ -49,8 +49,6 @@ export default function load() {
|
||||||
if (config.localDriveCapacityMb == null) config.localDriveCapacityMb = 256;
|
if (config.localDriveCapacityMb == null) config.localDriveCapacityMb = 256;
|
||||||
if (config.remoteDriveCapacityMb == null) config.remoteDriveCapacityMb = 8;
|
if (config.remoteDriveCapacityMb == null) config.remoteDriveCapacityMb = 8;
|
||||||
|
|
||||||
if (config.maxNoteTextLength == null) config.maxNoteTextLength = 1000;
|
|
||||||
|
|
||||||
return Object.assign(config, mixin);
|
return Object.assign(config, mixin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,6 @@ export type Source = {
|
||||||
engine: string;
|
engine: string;
|
||||||
timeout: number;
|
timeout: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
maxNoteTextLength?: number;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,4 +43,9 @@ export type IMeta = {
|
||||||
disableLocalTimeline?: boolean;
|
disableLocalTimeline?: boolean;
|
||||||
hidedTags?: string[];
|
hidedTags?: string[];
|
||||||
bannerUrl?: string;
|
bannerUrl?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Max allowed note text length in charactors
|
||||||
|
*/
|
||||||
|
maxNoteTextLength?: number;
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,6 @@ import Reaction from './note-reaction';
|
||||||
import { packMany as packFileMany, IDriveFile } from './drive-file';
|
import { packMany as packFileMany, IDriveFile } from './drive-file';
|
||||||
import Favorite from './favorite';
|
import Favorite from './favorite';
|
||||||
import Following from './following';
|
import Following from './following';
|
||||||
import config from '../config';
|
|
||||||
import Emoji from './emoji';
|
import Emoji from './emoji';
|
||||||
|
|
||||||
const Note = db.get<INote>('notes');
|
const Note = db.get<INote>('notes');
|
||||||
|
@ -27,10 +26,6 @@ Note.createIndex({ createdAt: -1 });
|
||||||
Note.createIndex({ score: -1 }, { sparse: true });
|
Note.createIndex({ score: -1 }, { sparse: true });
|
||||||
export default Note;
|
export default Note;
|
||||||
|
|
||||||
export function isValidText(text: string): boolean {
|
|
||||||
return length(text.trim()) <= config.maxNoteTextLength && text.trim() != '';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isValidCw(text: string): boolean {
|
export function isValidCw(text: string): boolean {
|
||||||
return length(text.trim()) <= 100;
|
return length(text.trim()) <= 100;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,13 @@ export const meta = {
|
||||||
'ja-JP': 'インスタンスの紹介文'
|
'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;
|
set.description = ps.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ps.maxNoteTextLength) {
|
||||||
|
set.maxNoteTextLength = ps.maxNoteTextLength;
|
||||||
|
}
|
||||||
|
|
||||||
await Meta.update({}, {
|
await Meta.update({}, {
|
||||||
$set: set
|
$set: set
|
||||||
}, { upsert: true });
|
}, { 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,
|
swPublickey: config.sw ? config.sw.public_key : null,
|
||||||
hidedTags: (me && me.isAdmin) ? met.hidedTags : undefined,
|
hidedTags: (me && me.isAdmin) ? met.hidedTags : undefined,
|
||||||
bannerUrl: met.bannerUrl,
|
bannerUrl: met.bannerUrl,
|
||||||
maxNoteTextLength: config.maxNoteTextLength,
|
maxNoteTextLength: met.maxNoteTextLength || 1000,
|
||||||
|
|
||||||
emojis: emojis,
|
emojis: emojis,
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,20 @@
|
||||||
import $ from 'cafy'; import ID, { transform, transformMany } from '../../../../misc/cafy-id';
|
import $ from 'cafy'; import ID, { transform, transformMany } from '../../../../misc/cafy-id';
|
||||||
const ms = require('ms');
|
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 User, { IUser } from '../../../../models/user';
|
||||||
import DriveFile, { IDriveFile } from '../../../../models/drive-file';
|
import DriveFile, { IDriveFile } from '../../../../models/drive-file';
|
||||||
import create from '../../../../services/note/create';
|
import create from '../../../../services/note/create';
|
||||||
import define from '../../define';
|
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 = {
|
export const meta = {
|
||||||
stability: 'stable',
|
stability: 'stable',
|
||||||
|
@ -40,7 +50,9 @@ export const meta = {
|
||||||
},
|
},
|
||||||
|
|
||||||
text: {
|
text: {
|
||||||
validator: $.str.optional.nullable.pipe(isValidText),
|
validator: $.str.optional.nullable.pipe(text =>
|
||||||
|
length(text.trim()) <= maxNoteTextLength && text.trim() != ''
|
||||||
|
),
|
||||||
default: null as any,
|
default: null as any,
|
||||||
desc: {
|
desc: {
|
||||||
'ja-JP': '投稿内容'
|
'ja-JP': '投稿内容'
|
||||||
|
|
Loading…
Reference in a new issue