]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/helpers/custom-validators/video-playlists.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / video-playlists.ts
1 import { exists } from './misc'
2 import validator from 'validator'
3 import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES } from '../../initializers/constants'
4
5 const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS
6
7 function isVideoPlaylistNameValid (value: any) {
8 return exists(value) && validator.isLength(value, PLAYLISTS_CONSTRAINT_FIELDS.NAME)
9 }
10
11 function isVideoPlaylistDescriptionValid (value: any) {
12 return value === null || (exists(value) && validator.isLength(value, PLAYLISTS_CONSTRAINT_FIELDS.DESCRIPTION))
13 }
14
15 function isVideoPlaylistPrivacyValid (value: number) {
16 return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[value] !== undefined
17 }
18
19 function isVideoPlaylistTimestampValid (value: any) {
20 return value === null || (exists(value) && validator.isInt('' + value, { min: 0 }))
21 }
22
23 function isVideoPlaylistTypeValid (value: any) {
24 return exists(value) && VIDEO_PLAYLIST_TYPES[value] !== undefined
25 }
26
27 // ---------------------------------------------------------------------------
28
29 export {
30 isVideoPlaylistNameValid,
31 isVideoPlaylistDescriptionValid,
32 isVideoPlaylistPrivacyValid,
33 isVideoPlaylistTimestampValid,
34 isVideoPlaylistTypeValid
35 }