1 import { exists } from './misc'
2 import * as validator from 'validator'
3 import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES } from '../../initializers'
4 import * as express from 'express'
5 import { VideoPlaylistModel } from '../../models/video/video-playlist'
7 const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS
9 function isVideoPlaylistNameValid (value: any) {
10 return exists(value) && validator.isLength(value, PLAYLISTS_CONSTRAINT_FIELDS.NAME)
13 function isVideoPlaylistDescriptionValid (value: any) {
14 return value === null || (exists(value) && validator.isLength(value, PLAYLISTS_CONSTRAINT_FIELDS.DESCRIPTION))
17 function isVideoPlaylistPrivacyValid (value: number) {
18 return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[ value ] !== undefined
21 function isVideoPlaylistTimestampValid (value: any) {
22 return value === null || (exists(value) && validator.isInt('' + value, { min: 0 }))
25 function isVideoPlaylistTypeValid (value: any) {
26 return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined
29 async function isVideoPlaylistExist (id: number | string, res: express.Response) {
30 const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined)
34 .json({ error: 'Video playlist not found' })
40 res.locals.videoPlaylist = videoPlaylist
44 // ---------------------------------------------------------------------------
48 isVideoPlaylistNameValid,
49 isVideoPlaylistDescriptionValid,
50 isVideoPlaylistPrivacyValid,
51 isVideoPlaylistTimestampValid,
52 isVideoPlaylistTypeValid