aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/activitypub/playlist.ts6
-rw-r--r--server/helpers/custom-validators/video-playlists.ts17
2 files changed, 17 insertions, 6 deletions
diff --git a/server/helpers/custom-validators/activitypub/playlist.ts b/server/helpers/custom-validators/activitypub/playlist.ts
index ecdc7975e..6c7bdb193 100644
--- a/server/helpers/custom-validators/activitypub/playlist.ts
+++ b/server/helpers/custom-validators/activitypub/playlist.ts
@@ -1,4 +1,4 @@
1import { exists } from '../misc' 1import { exists, isDateValid } from '../misc'
2import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' 2import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
3import * as validator from 'validator' 3import * as validator from 'validator'
4import { PlaylistElementObject } from '../../../../shared/models/activitypub/objects/playlist-element-object' 4import { PlaylistElementObject } from '../../../../shared/models/activitypub/objects/playlist-element-object'
@@ -7,7 +7,9 @@ import { isActivityPubUrlValid } from './misc'
7function isPlaylistObjectValid (object: PlaylistObject) { 7function isPlaylistObjectValid (object: PlaylistObject) {
8 return exists(object) && 8 return exists(object) &&
9 object.type === 'Playlist' && 9 object.type === 'Playlist' &&
10 validator.isInt(object.totalItems + '') 10 validator.isInt(object.totalItems + '') &&
11 isDateValid(object.published) &&
12 isDateValid(object.updated)
11} 13}
12 14
13function isPlaylistElementObjectValid (object: PlaylistElementObject) { 15function isPlaylistElementObjectValid (object: PlaylistElementObject) {
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}