aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-15 14:46:26 +0100
committerChocobozzz <me@florianbigard.com>2018-02-15 15:29:07 +0100
commit2422c46b27790d94fd29a7092170cee5a1b56008 (patch)
treed5c1942ce20cadb27a551d87c789edfe92f5b105 /server/helpers/custom-validators
parent34cbef8c6cc912143a421413bdd832c4adcc556a (diff)
downloadPeerTube-2422c46b27790d94fd29a7092170cee5a1b56008.tar.gz
PeerTube-2422c46b27790d94fd29a7092170cee5a1b56008.tar.zst
PeerTube-2422c46b27790d94fd29a7092170cee5a1b56008.zip
Implement support field in video and video channel
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/accounts.ts7
-rw-r--r--server/helpers/custom-validators/users.ts5
-rw-r--r--server/helpers/custom-validators/video-channels.ts5
-rw-r--r--server/helpers/custom-validators/videos.ts7
4 files changed, 22 insertions, 2 deletions
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'
3import 'express-validator' 3import 'express-validator'
4import * as validator from 'validator' 4import * as validator from 'validator'
5import { AccountModel } from '../../models/account/account' 5import { AccountModel } from '../../models/account/account'
6import { isUserUsernameValid } from './users' 6import { isUserDescriptionValid, isUserUsernameValid } from './users'
7 7
8function isAccountNameValid (value: string) { 8function isAccountNameValid (value: string) {
9 return isUserUsernameValid(value) 9 return isUserUsernameValid(value)
10} 10}
11 11
12function isAccountDescriptionValid (value: string) {
13 return isUserDescriptionValid(value)
14}
15
12function isAccountIdExist (id: number | string, res: Response) { 16function isAccountIdExist (id: number | string, res: Response) {
13 let promise: Bluebird<AccountModel> 17 let promise: Bluebird<AccountModel>
14 18
@@ -48,5 +52,6 @@ async function isAccountExist (p: Bluebird<AccountModel>, res: Response) {
48export { 52export {
49 isAccountIdExist, 53 isAccountIdExist,
50 isLocalAccountNameExist, 54 isLocalAccountNameExist,
55 isAccountDescriptionValid,
51 isAccountNameValid 56 isAccountNameValid
52} 57}
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) {
21 return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`)) 21 return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`))
22} 22}
23 23
24function isUserDescriptionValid (value: string) {
25 return value === null || (exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.USERS.DESCRIPTION))
26}
27
24function isBoolean (value: any) { 28function isBoolean (value: any) {
25 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) 29 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
26} 30}
@@ -54,5 +58,6 @@ export {
54 isUserUsernameValid, 58 isUserUsernameValid,
55 isUserDisplayNSFWValid, 59 isUserDisplayNSFWValid,
56 isUserAutoPlayVideoValid, 60 isUserAutoPlayVideoValid,
61 isUserDescriptionValid,
57 isAvatarFile 62 isAvatarFile
58} 63}
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) {
16 return exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.NAME) 16 return exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.NAME)
17} 17}
18 18
19function isVideoChannelSupportValid (value: string) {
20 return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT))
21}
22
19async function isVideoChannelExist (id: string, res: express.Response) { 23async function isVideoChannelExist (id: string, res: express.Response) {
20 let videoChannel: VideoChannelModel 24 let videoChannel: VideoChannelModel
21 if (validator.isInt(id)) { 25 if (validator.isInt(id)) {
@@ -41,5 +45,6 @@ async function isVideoChannelExist (id: string, res: express.Response) {
41export { 45export {
42 isVideoChannelDescriptionValid, 46 isVideoChannelDescriptionValid,
43 isVideoChannelNameValid, 47 isVideoChannelNameValid,
48 isVideoChannelSupportValid,
44 isVideoChannelExist 49 isVideoChannelExist
45} 50}
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) {
42 return value === null || (exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)) 42 return value === null || (exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION))
43} 43}
44 44
45function isVideoSupportValid (value: string) {
46 return value === null || (exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.SUPPORT))
47}
48
45function isVideoNameValid (value: string) { 49function isVideoNameValid (value: string) {
46 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) 50 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME)
47} 51}
@@ -140,5 +144,6 @@ export {
140 isVideoFileResolutionValid, 144 isVideoFileResolutionValid,
141 isVideoFileSizeValid, 145 isVideoFileSizeValid,
142 isVideoExist, 146 isVideoExist,
143 isVideoImage 147 isVideoImage,
148 isVideoSupportValid
144} 149}