aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-playlists.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-05 10:58:44 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-03-18 11:17:59 +0100
commitdf0b219d36bf6852cdf2a7ad09ed4a41c6bccefa (patch)
treec4984e854f5dc18e5c27afd73b843bd52c143034 /server/helpers/custom-validators/video-playlists.ts
parent07b1a18aa678d260009a93e36606c5c5f585723d (diff)
downloadPeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.tar.gz
PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.tar.zst
PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.zip
Add playlist rest tests
Diffstat (limited to 'server/helpers/custom-validators/video-playlists.ts')
-rw-r--r--server/helpers/custom-validators/video-playlists.ts17
1 files changed, 13 insertions, 4 deletions
diff --git a/server/helpers/custom-validators/video-playlists.ts b/server/helpers/custom-validators/video-playlists.ts
index 0f5af4ec0..c217a39bf 100644
--- a/server/helpers/custom-validators/video-playlists.ts
+++ b/server/helpers/custom-validators/video-playlists.ts
@@ -1,9 +1,8 @@
1import { exists } from './misc' 1import { exists } from './misc'
2import * as validator from 'validator' 2import * as validator from 'validator'
3import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers' 3import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES } from '../../initializers'
4import * as express from 'express' 4import * as express from 'express'
5import { VideoPlaylistModel } from '../../models/video/video-playlist' 5import { VideoPlaylistModel } from '../../models/video/video-playlist'
6import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
7 6
8const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS 7const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS
9 8
@@ -19,8 +18,16 @@ function isVideoPlaylistPrivacyValid (value: number) {
19 return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[ value ] !== undefined 18 return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[ value ] !== undefined
20} 19}
21 20
21function isVideoPlaylistTimestampValid (value: any) {
22 return value === null || (exists(value) && validator.isInt('' + value, { min: 0 }))
23}
24
25function isVideoPlaylistTypeValid (value: any) {
26 return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined
27}
28
22async function isVideoPlaylistExist (id: number | string, res: express.Response) { 29async function isVideoPlaylistExist (id: number | string, res: express.Response) {
23 const videoPlaylist = await VideoPlaylistModel.load(id, undefined) 30 const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined)
24 31
25 if (!videoPlaylist) { 32 if (!videoPlaylist) {
26 res.status(404) 33 res.status(404)
@@ -40,5 +47,7 @@ export {
40 isVideoPlaylistExist, 47 isVideoPlaylistExist,
41 isVideoPlaylistNameValid, 48 isVideoPlaylistNameValid,
42 isVideoPlaylistDescriptionValid, 49 isVideoPlaylistDescriptionValid,
43 isVideoPlaylistPrivacyValid 50 isVideoPlaylistPrivacyValid,
51 isVideoPlaylistTimestampValid,
52 isVideoPlaylistTypeValid
44} 53}