aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-playlists.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/video-playlists.ts')
-rw-r--r--server/helpers/custom-validators/video-playlists.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/video-playlists.ts b/server/helpers/custom-validators/video-playlists.ts
new file mode 100644
index 000000000..0f5af4ec0
--- /dev/null
+++ b/server/helpers/custom-validators/video-playlists.ts
@@ -0,0 +1,44 @@
1import { exists } from './misc'
2import * as validator from 'validator'
3import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers'
4import * as express from 'express'
5import { VideoPlaylistModel } from '../../models/video/video-playlist'
6import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
7
8const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS
9
10function isVideoPlaylistNameValid (value: any) {
11 return exists(value) && validator.isLength(value, PLAYLISTS_CONSTRAINT_FIELDS.NAME)
12}
13
14function isVideoPlaylistDescriptionValid (value: any) {
15 return value === null || (exists(value) && validator.isLength(value, PLAYLISTS_CONSTRAINT_FIELDS.DESCRIPTION))
16}
17
18function isVideoPlaylistPrivacyValid (value: number) {
19 return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[ value ] !== undefined
20}
21
22async function isVideoPlaylistExist (id: number | string, res: express.Response) {
23 const videoPlaylist = await VideoPlaylistModel.load(id, undefined)
24
25 if (!videoPlaylist) {
26 res.status(404)
27 .json({ error: 'Video playlist not found' })
28 .end()
29
30 return false
31 }
32
33 res.locals.videoPlaylist = videoPlaylist
34 return true
35}
36
37// ---------------------------------------------------------------------------
38
39export {
40 isVideoPlaylistExist,
41 isVideoPlaylistNameValid,
42 isVideoPlaylistDescriptionValid,
43 isVideoPlaylistPrivacyValid
44}