aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/videos')
-rw-r--r--server/middlewares/validators/videos/video-playlists.ts48
1 files changed, 40 insertions, 8 deletions
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts
index 0e97c8dc0..796c63748 100644
--- a/server/middlewares/validators/videos/video-playlists.ts
+++ b/server/middlewares/validators/videos/video-playlists.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, ValidationChain } from 'express-validator/check' 2import { body, param, query, ValidationChain } from 'express-validator/check'
3import { UserRight, VideoPrivacy } from '../../../../shared' 3import { UserRight } from '../../../../shared'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { UserModel } from '../../../models/account/user' 5import { UserModel } from '../../../models/account/user'
6import { areValidationErrors } from '../utils' 6import { areValidationErrors } from '../utils'
@@ -11,7 +11,9 @@ import {
11 isVideoPlaylistDescriptionValid, 11 isVideoPlaylistDescriptionValid,
12 isVideoPlaylistExist, 12 isVideoPlaylistExist,
13 isVideoPlaylistNameValid, 13 isVideoPlaylistNameValid,
14 isVideoPlaylistPrivacyValid 14 isVideoPlaylistPrivacyValid,
15 isVideoPlaylistTimestampValid,
16 isVideoPlaylistTypeValid
15} from '../../../helpers/custom-validators/video-playlists' 17} from '../../../helpers/custom-validators/video-playlists'
16import { VideoPlaylistModel } from '../../../models/video/video-playlist' 18import { VideoPlaylistModel } from '../../../models/video/video-playlist'
17import { cleanUpReqFiles } from '../../../helpers/express-utils' 19import { cleanUpReqFiles } from '../../../helpers/express-utils'
@@ -20,6 +22,7 @@ import { VideoPlaylistElementModel } from '../../../models/video/video-playlist-
20import { VideoModel } from '../../../models/video/video' 22import { VideoModel } from '../../../models/video/video'
21import { authenticatePromiseIfNeeded } from '../../oauth' 23import { authenticatePromiseIfNeeded } from '../../oauth'
22import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 24import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
25import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
23 26
24const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ 27const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([
25 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 28 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -56,6 +59,12 @@ const videoPlaylistsUpdateValidator = getCommonPlaylistEditAttributes().concat([
56 .json({ error: 'Cannot set "private" a video playlist that was not private.' }) 59 .json({ error: 'Cannot set "private" a video playlist that was not private.' })
57 } 60 }
58 61
62 if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) {
63 cleanUpReqFiles(req)
64 return res.status(409)
65 .json({ error: 'Cannot update a watch later playlist.' })
66 }
67
59 if (req.body.videoChannelId && !await isVideoChannelIdExist(req.body.videoChannelId, res)) return cleanUpReqFiles(req) 68 if (req.body.videoChannelId && !await isVideoChannelIdExist(req.body.videoChannelId, res)) return cleanUpReqFiles(req)
60 69
61 return next() 70 return next()
@@ -72,6 +81,13 @@ const videoPlaylistsDeleteValidator = [
72 if (areValidationErrors(req, res)) return 81 if (areValidationErrors(req, res)) return
73 82
74 if (!await isVideoPlaylistExist(req.params.playlistId, res)) return 83 if (!await isVideoPlaylistExist(req.params.playlistId, res)) return
84
85 const videoPlaylist: VideoPlaylistModel = res.locals.videoPlaylist
86 if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) {
87 return res.status(409)
88 .json({ error: 'Cannot delete a watch later playlist.' })
89 }
90
75 if (!checkUserCanManageVideoPlaylist(res.locals.oauth.token.User, res.locals.videoPlaylist, UserRight.REMOVE_ANY_VIDEO_PLAYLIST, res)) { 91 if (!checkUserCanManageVideoPlaylist(res.locals.oauth.token.User, res.locals.videoPlaylist, UserRight.REMOVE_ANY_VIDEO_PLAYLIST, res)) {
76 return 92 return
77 } 93 }
@@ -127,10 +143,10 @@ const videoPlaylistsAddVideoValidator = [
127 .custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid'), 143 .custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid'),
128 body('startTimestamp') 144 body('startTimestamp')
129 .optional() 145 .optional()
130 .isInt({ min: 0 }).withMessage('Should have a valid start timestamp'), 146 .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid start timestamp'),
131 body('stopTimestamp') 147 body('stopTimestamp')
132 .optional() 148 .optional()
133 .isInt({ min: 0 }).withMessage('Should have a valid stop timestamp'), 149 .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid stop timestamp'),
134 150
135 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 151 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
136 logger.debug('Checking videoPlaylistsAddVideoValidator parameters', { parameters: req.params }) 152 logger.debug('Checking videoPlaylistsAddVideoValidator parameters', { parameters: req.params })
@@ -167,10 +183,10 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [
167 .custom(isIdOrUUIDValid).withMessage('Should have an video id/uuid'), 183 .custom(isIdOrUUIDValid).withMessage('Should have an video id/uuid'),
168 body('startTimestamp') 184 body('startTimestamp')
169 .optional() 185 .optional()
170 .isInt({ min: 0 }).withMessage('Should have a valid start timestamp'), 186 .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid start timestamp'),
171 body('stopTimestamp') 187 body('stopTimestamp')
172 .optional() 188 .optional()
173 .isInt({ min: 0 }).withMessage('Should have a valid stop timestamp'), 189 .custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid stop timestamp'),
174 190
175 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 191 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
176 logger.debug('Checking videoPlaylistsRemoveVideoValidator parameters', { parameters: req.params }) 192 logger.debug('Checking videoPlaylistsRemoveVideoValidator parameters', { parameters: req.params })
@@ -275,6 +291,20 @@ const videoPlaylistsReorderVideosValidator = [
275 } 291 }
276] 292]
277 293
294const commonVideoPlaylistFiltersValidator = [
295 query('playlistType')
296 .optional()
297 .custom(isVideoPlaylistTypeValid).withMessage('Should have a valid playlist type'),
298
299 (req: express.Request, res: express.Response, next: express.NextFunction) => {
300 logger.debug('Checking commonVideoPlaylistFiltersValidator parameters', { parameters: req.params })
301
302 if (areValidationErrors(req, res)) return
303
304 return next()
305 }
306]
307
278// --------------------------------------------------------------------------- 308// ---------------------------------------------------------------------------
279 309
280export { 310export {
@@ -287,7 +317,9 @@ export {
287 videoPlaylistsUpdateOrRemoveVideoValidator, 317 videoPlaylistsUpdateOrRemoveVideoValidator,
288 videoPlaylistsReorderVideosValidator, 318 videoPlaylistsReorderVideosValidator,
289 319
290 videoPlaylistElementAPGetValidator 320 videoPlaylistElementAPGetValidator,
321
322 commonVideoPlaylistFiltersValidator
291} 323}
292 324
293// --------------------------------------------------------------------------- 325// ---------------------------------------------------------------------------