From 75c4c844e6d679cd94da59525801fdd879e780c1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 30 Mar 2018 11:24:07 +0900 Subject: [PATCH] cw --- src/client/docs/api/endpoints/posts/create.yaml | 6 ++++++ src/models/post.ts | 5 +++++ src/server/api/endpoints/posts/create.ts | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/client/docs/api/endpoints/posts/create.yaml b/src/client/docs/api/endpoints/posts/create.yaml index 11d9f40c5..d2d6e27fc 100644 --- a/src/client/docs/api/endpoints/posts/create.yaml +++ b/src/client/docs/api/endpoints/posts/create.yaml @@ -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 diff --git a/src/models/post.ts b/src/models/post.ts index 833e59932..9bc0c1d3b 100644 --- a/src/models/post.ts +++ b/src/models/post.ts @@ -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; diff --git a/src/server/api/endpoints/posts/create.ts b/src/server/api/endpoints/posts/create.ts index 6b2957ae6..170b66719 100644 --- a/src/server/api/endpoints/posts/create.ts +++ b/src/server/api/endpoints/posts/create.ts @@ -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,