diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-03 10:12:36 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-03 10:38:19 +0100 |
commit | 47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04 (patch) | |
tree | 25e2836baf3dfce6f422192d98332db1bfe65890 /server/middlewares/validators/video-comments.ts | |
parent | c5911fd347c76e8bdc05ea9f3ee9efed4a58c236 (diff) | |
download | PeerTube-47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04.tar.gz PeerTube-47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04.tar.zst PeerTube-47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04.zip |
Add ability to disable video comments
Diffstat (limited to 'server/middlewares/validators/video-comments.ts')
-rw-r--r-- | server/middlewares/validators/video-comments.ts | 14 |
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 | |||
152 | function 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 | } | ||