From 2422c46b27790d94fd29a7092170cee5a1b56008 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Feb 2018 14:46:26 +0100 Subject: Implement support field in video and video channel --- server/helpers/activitypub.ts | 3 ++- server/helpers/custom-validators/accounts.ts | 7 ++++++- server/helpers/custom-validators/users.ts | 5 +++++ server/helpers/custom-validators/video-channels.ts | 5 +++++ server/helpers/custom-validators/videos.ts | 7 ++++++- 5 files changed, 24 insertions(+), 3 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index eaee324eb..d64a6dd78 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts @@ -19,7 +19,8 @@ function activityPubContextify (data: T) { 'language': 'http://schema.org/inLanguage', 'views': 'http://schema.org/Number', 'size': 'http://schema.org/Number', - 'commentsEnabled': 'http://schema.org/Boolean' + 'commentsEnabled': 'http://schema.org/Boolean', + 'support': 'http://schema.org/Text' }, { likes: { diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts index 8dc5d1f0d..a46ffc162 100644 --- a/server/helpers/custom-validators/accounts.ts +++ b/server/helpers/custom-validators/accounts.ts @@ -3,12 +3,16 @@ import { Response } from 'express' import 'express-validator' import * as validator from 'validator' import { AccountModel } from '../../models/account/account' -import { isUserUsernameValid } from './users' +import { isUserDescriptionValid, isUserUsernameValid } from './users' function isAccountNameValid (value: string) { return isUserUsernameValid(value) } +function isAccountDescriptionValid (value: string) { + return isUserDescriptionValid(value) +} + function isAccountIdExist (id: number | string, res: Response) { let promise: Bluebird @@ -48,5 +52,6 @@ async function isAccountExist (p: Bluebird, res: Response) { export { isAccountIdExist, isLocalAccountNameExist, + isAccountDescriptionValid, isAccountNameValid } diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index e805313f8..bbc7cc199 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -21,6 +21,10 @@ function isUserUsernameValid (value: string) { return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`)) } +function isUserDescriptionValid (value: string) { + return value === null || (exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.USERS.DESCRIPTION)) +} + function isBoolean (value: any) { return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) } @@ -54,5 +58,6 @@ export { isUserUsernameValid, isUserDisplayNSFWValid, isUserAutoPlayVideoValid, + isUserDescriptionValid, isAvatarFile } diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts index 6bc96bf51..2a6f56840 100644 --- a/server/helpers/custom-validators/video-channels.ts +++ b/server/helpers/custom-validators/video-channels.ts @@ -16,6 +16,10 @@ function isVideoChannelNameValid (value: string) { return exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.NAME) } +function isVideoChannelSupportValid (value: string) { + return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT)) +} + async function isVideoChannelExist (id: string, res: express.Response) { let videoChannel: VideoChannelModel if (validator.isInt(id)) { @@ -41,5 +45,6 @@ async function isVideoChannelExist (id: string, res: express.Response) { export { isVideoChannelDescriptionValid, isVideoChannelNameValid, + isVideoChannelSupportValid, isVideoChannelExist } diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 8ef3a3c64..a46d715ba 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -42,6 +42,10 @@ function isVideoDescriptionValid (value: string) { return value === null || (exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)) } +function isVideoSupportValid (value: string) { + return value === null || (exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.SUPPORT)) +} + function isVideoNameValid (value: string) { return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) } @@ -140,5 +144,6 @@ export { isVideoFileResolutionValid, isVideoFileSizeValid, isVideoExist, - isVideoImage + isVideoImage, + isVideoSupportValid } -- cgit v1.2.3