aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/video-comments.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/video-comments.ts')
-rw-r--r--server/middlewares/validators/video-comments.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/server/middlewares/validators/video-comments.ts b/server/middlewares/validators/video-comments.ts
index fdd092571..ade0b7b9f 100644
--- a/server/middlewares/validators/video-comments.ts
+++ b/server/middlewares/validators/video-comments.ts
@@ -45,6 +45,7 @@ const addVideoCommentThreadValidator = [
45 45
46 if (areValidationErrors(req, res)) return 46 if (areValidationErrors(req, res)) return
47 if (!await isVideoExist(req.params.videoId, res)) return 47 if (!await isVideoExist(req.params.videoId, res)) return
48 if (!isVideoCommentsEnabled(res.locals.video, res)) return
48 49
49 return next() 50 return next()
50 } 51 }
@@ -60,6 +61,7 @@ const addVideoCommentReplyValidator = [
60 61
61 if (areValidationErrors(req, res)) return 62 if (areValidationErrors(req, res)) return
62 if (!await isVideoExist(req.params.videoId, res)) return 63 if (!await isVideoExist(req.params.videoId, res)) return
64 if (!isVideoCommentsEnabled(res.locals.video, res)) return
63 if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return 65 if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return
64 66
65 return next() 67 return next()
@@ -146,3 +148,15 @@ async function isVideoCommentExist (id: number, video: VideoModel, res: express.
146 res.locals.videoComment = videoComment 148 res.locals.videoComment = videoComment
147 return true 149 return true
148} 150}
151
152function isVideoCommentsEnabled (video: VideoModel, res: express.Response) {
153 if (video.commentsEnabled !== true) {
154 res.status(409)
155 .json({ error: 'Video comments are disabled for this video.' })
156 .end()
157
158 return false
159 }
160
161 return true
162}