]>
Commit | Line | Data |
---|---|---|
418d092a C |
1 | import { exists } from './misc' |
2 | import * as validator from 'validator' | |
df0b219d | 3 | import { CONSTRAINTS_FIELDS, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES } from '../../initializers' |
418d092a C |
4 | import * as express from 'express' |
5 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | |
418d092a C |
6 | |
7 | const PLAYLISTS_CONSTRAINT_FIELDS = CONSTRAINTS_FIELDS.VIDEO_PLAYLISTS | |
8 | ||
9 | function isVideoPlaylistNameValid (value: any) { | |
10 | return exists(value) && validator.isLength(value, PLAYLISTS_CONSTRAINT_FIELDS.NAME) | |
11 | } | |
12 | ||
13 | function isVideoPlaylistDescriptionValid (value: any) { | |
14 | return value === null || (exists(value) && validator.isLength(value, PLAYLISTS_CONSTRAINT_FIELDS.DESCRIPTION)) | |
15 | } | |
16 | ||
17 | function isVideoPlaylistPrivacyValid (value: number) { | |
18 | return validator.isInt(value + '') && VIDEO_PLAYLIST_PRIVACIES[ value ] !== undefined | |
19 | } | |
20 | ||
df0b219d C |
21 | function isVideoPlaylistTimestampValid (value: any) { |
22 | return value === null || (exists(value) && validator.isInt('' + value, { min: 0 })) | |
23 | } | |
24 | ||
25 | function isVideoPlaylistTypeValid (value: any) { | |
26 | return exists(value) && VIDEO_PLAYLIST_TYPES[ value ] !== undefined | |
27 | } | |
28 | ||
09979f89 C |
29 | async function isVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { |
30 | const videoPlaylist = fetchType === 'summary' | |
31 | ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined) | |
32 | : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) | |
418d092a C |
33 | |
34 | if (!videoPlaylist) { | |
35 | res.status(404) | |
36 | .json({ error: 'Video playlist not found' }) | |
37 | .end() | |
38 | ||
39 | return false | |
40 | } | |
41 | ||
42 | res.locals.videoPlaylist = videoPlaylist | |
43 | return true | |
44 | } | |
45 | ||
46 | // --------------------------------------------------------------------------- | |
47 | ||
48 | export { | |
49 | isVideoPlaylistExist, | |
50 | isVideoPlaylistNameValid, | |
51 | isVideoPlaylistDescriptionValid, | |
df0b219d C |
52 | isVideoPlaylistPrivacyValid, |
53 | isVideoPlaylistTimestampValid, | |
54 | isVideoPlaylistTypeValid | |
418d092a | 55 | } |