aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/redundancy.ts18
-rw-r--r--server/middlewares/validators/users.ts3
-rw-r--r--server/middlewares/validators/videos/video-comments.ts6
3 files changed, 20 insertions, 7 deletions
diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts
index e65d3b8d3..8098e3a44 100644
--- a/server/middlewares/validators/redundancy.ts
+++ b/server/middlewares/validators/redundancy.ts
@@ -25,8 +25,12 @@ const videoFileRedundancyGetValidator = [
25 if (!await doesVideoExist(req.params.videoId, res)) return 25 if (!await doesVideoExist(req.params.videoId, res)) return
26 26
27 const video = res.locals.videoAll 27 const video = res.locals.videoAll
28
29 const paramResolution = req.params.resolution as unknown as number // We casted to int above
30 const paramFPS = req.params.fps as unknown as number // We casted to int above
31
28 const videoFile = video.VideoFiles.find(f => { 32 const videoFile = video.VideoFiles.find(f => {
29 return f.resolution === req.params.resolution && (!req.params.fps || f.fps === req.params.fps) 33 return f.resolution === paramResolution && (!req.params.fps || paramFPS)
30 }) 34 })
31 35
32 if (!videoFile) return res.status(404).json({ error: 'Video file not found.' }) 36 if (!videoFile) return res.status(404).json({ error: 'Video file not found.' })
@@ -41,8 +45,12 @@ const videoFileRedundancyGetValidator = [
41] 45]
42 46
43const videoPlaylistRedundancyGetValidator = [ 47const videoPlaylistRedundancyGetValidator = [
44 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), 48 param('videoId')
45 param('streamingPlaylistType').custom(exists).withMessage('Should have a valid streaming playlist type'), 49 .custom(isIdOrUUIDValid)
50 .not().isEmpty().withMessage('Should have a valid video id'),
51 param('streamingPlaylistType')
52 .customSanitizer(toIntOrNull)
53 .custom(exists).withMessage('Should have a valid streaming playlist type'),
46 54
47 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 55 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
48 logger.debug('Checking videoPlaylistRedundancyGetValidator parameters', { parameters: req.params }) 56 logger.debug('Checking videoPlaylistRedundancyGetValidator parameters', { parameters: req.params })
@@ -51,7 +59,9 @@ const videoPlaylistRedundancyGetValidator = [
51 if (!await doesVideoExist(req.params.videoId, res)) return 59 if (!await doesVideoExist(req.params.videoId, res)) return
52 60
53 const video = res.locals.videoAll 61 const video = res.locals.videoAll
54 const videoStreamingPlaylist = video.VideoStreamingPlaylists.find(p => p === req.params.streamingPlaylistType) 62
63 const paramPlaylistType = req.params.streamingPlaylistType as unknown as number // We casted to int above
64 const videoStreamingPlaylist = video.VideoStreamingPlaylists.find(p => p.type === paramPlaylistType)
55 65
56 if (!videoStreamingPlaylist) return res.status(404).json({ error: 'Video playlist not found.' }) 66 if (!videoStreamingPlaylist) return res.status(404).json({ error: 'Video playlist not found.' })
57 res.locals.videoStreamingPlaylist = videoStreamingPlaylist 67 res.locals.videoStreamingPlaylist = videoStreamingPlaylist
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index b3466333c..804d1410e 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -448,7 +448,8 @@ export {
448 448
449// --------------------------------------------------------------------------- 449// ---------------------------------------------------------------------------
450 450
451function checkUserIdExist (id: number, res: express.Response) { 451function checkUserIdExist (idArg: number | string, res: express.Response) {
452 const id = parseInt(idArg + '', 10)
452 return checkUserExist(() => UserModel.loadById(id), res) 453 return checkUserExist(() => UserModel.loadById(id), res)
453} 454}
454 455
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts
index 8adbb02ba..1d81eb5d8 100644
--- a/server/middlewares/validators/videos/video-comments.ts
+++ b/server/middlewares/validators/videos/video-comments.ts
@@ -120,7 +120,8 @@ export {
120 120
121// --------------------------------------------------------------------------- 121// ---------------------------------------------------------------------------
122 122
123async function doesVideoCommentThreadExist (id: number, video: MVideoId, res: express.Response) { 123async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) {
124 const id = parseInt(idArg + '', 10)
124 const videoComment = await VideoCommentModel.loadById(id) 125 const videoComment = await VideoCommentModel.loadById(id)
125 126
126 if (!videoComment) { 127 if (!videoComment) {
@@ -151,7 +152,8 @@ async function doesVideoCommentThreadExist (id: number, video: MVideoId, res: ex
151 return true 152 return true
152} 153}
153 154
154async function doesVideoCommentExist (id: number, video: MVideoId, res: express.Response) { 155async function doesVideoCommentExist (idArg: number | string, video: MVideoId, res: express.Response) {
156 const id = parseInt(idArg + '', 10)
155 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) 157 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
156 158
157 if (!videoComment) { 159 if (!videoComment) {