This commit is contained in:
syuilo 2018-03-30 11:24:07 +09:00
parent 5c3ca62426
commit 75c4c844e6
3 changed files with 17 additions and 1 deletions

View file

@ -11,6 +11,12 @@ params:
desc:
ja: "投稿の本文"
en: "The text of your post"
- name: "cw"
type: "string"
optional: true
desc:
ja: "コンテンツの警告。このパラメータを指定すると設定したテキストで投稿のコンテンツを隠す事が出来ます。"
en: "Content Warning"
- name: "mediaIds"
type: "id(DriveFile)[]"
optional: true

View file

@ -18,6 +18,10 @@ export function isValidText(text: string): boolean {
return text.length <= 1000 && text.trim() != '';
}
export function isValidCw(text: string): boolean {
return text.length <= 100 && text.trim() != '';
}
export type IPost = {
_id: mongo.ObjectID;
channelId: mongo.ObjectID;
@ -27,6 +31,7 @@ export type IPost = {
repostId: mongo.ObjectID;
poll: any; // todo
text: string;
cw: string;
userId: mongo.ObjectID;
appId: mongo.ObjectID;
viaMobile: boolean;

View file

@ -4,7 +4,7 @@
import $ from 'cafy';
import deepEqual = require('deep-equal');
import parse from '../../../../common/text';
import { default as Post, IPost, isValidText } from '../../../../models/post';
import { default as Post, IPost, isValidText, isValidCw } from '../../../../models/post';
import { default as User, ILocalAccount, IUser } from '../../../../models/user';
import { default as Channel, IChannel } from '../../../../models/channel';
import Following from '../../../../models/following';
@ -33,6 +33,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
if (textErr) return rej('invalid text');
// Get 'cw' parameter
const [cw, cwErr] = $(params.cw).optional.string().pipe(isValidCw).$;
if (cwErr) return rej('invalid cw');
// Get 'viaMobile' parameter
const [viaMobile = false, viaMobileErr] = $(params.viaMobile).optional.boolean().$;
if (viaMobileErr) return rej('invalid viaMobile');
@ -255,6 +259,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
repostId: repost ? repost._id : undefined,
poll: poll,
text: text,
cw: cw,
tags: tags,
userId: user._id,
appId: app ? app._id : null,