diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 11:16:08 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 11:16:08 +0100 |
commit | da854ddd502cd70685ef779c673b9e63757b8aa0 (patch) | |
tree | 21501d170cceaa044a5f23449cbd2eb47fd6415d /server/middlewares/validators/video-comments.ts | |
parent | f40bbe3146553ef45515ee6b6d93ce6028f045ca (diff) | |
download | PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.tar.gz PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.tar.zst PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.zip |
Propagate old comment on new follow
Diffstat (limited to 'server/middlewares/validators/video-comments.ts')
-rw-r--r-- | server/middlewares/validators/video-comments.ts | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/server/middlewares/validators/video-comments.ts b/server/middlewares/validators/video-comments.ts index 1d19fac58..fdd092571 100644 --- a/server/middlewares/validators/video-comments.ts +++ b/server/middlewares/validators/video-comments.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | ||
4 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | 3 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' |
5 | import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments' | 4 | import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments' |
6 | import { isVideoExist } from '../../helpers/custom-validators/videos' | 5 | import { isVideoExist } from '../../helpers/custom-validators/videos' |
6 | import { logger } from '../../helpers/logger' | ||
7 | import { VideoModel } from '../../models/video/video' | 7 | import { VideoModel } from '../../models/video/video' |
8 | import { VideoCommentModel } from '../../models/video/video-comment' | 8 | import { VideoCommentModel } from '../../models/video/video-comment' |
9 | import { areValidationErrors } from './utils' | 9 | import { areValidationErrors } from './utils' |
@@ -66,13 +66,29 @@ const addVideoCommentReplyValidator = [ | |||
66 | } | 66 | } |
67 | ] | 67 | ] |
68 | 68 | ||
69 | const videoCommentGetValidator = [ | ||
70 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | ||
71 | param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), | ||
72 | |||
73 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
74 | logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) | ||
75 | |||
76 | if (areValidationErrors(req, res)) return | ||
77 | if (!await isVideoExist(req.params.videoId, res)) return | ||
78 | if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return | ||
79 | |||
80 | return next() | ||
81 | } | ||
82 | ] | ||
83 | |||
69 | // --------------------------------------------------------------------------- | 84 | // --------------------------------------------------------------------------- |
70 | 85 | ||
71 | export { | 86 | export { |
72 | listVideoCommentThreadsValidator, | 87 | listVideoCommentThreadsValidator, |
73 | listVideoThreadCommentsValidator, | 88 | listVideoThreadCommentsValidator, |
74 | addVideoCommentThreadValidator, | 89 | addVideoCommentThreadValidator, |
75 | addVideoCommentReplyValidator | 90 | addVideoCommentReplyValidator, |
91 | videoCommentGetValidator | ||
76 | } | 92 | } |
77 | 93 | ||
78 | // --------------------------------------------------------------------------- | 94 | // --------------------------------------------------------------------------- |
@@ -109,7 +125,7 @@ async function isVideoCommentThreadExist (id: number, video: VideoModel, res: ex | |||
109 | } | 125 | } |
110 | 126 | ||
111 | async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { | 127 | async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { |
112 | const videoComment = await VideoCommentModel.loadById(id) | 128 | const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) |
113 | 129 | ||
114 | if (!videoComment) { | 130 | if (!videoComment) { |
115 | res.status(404) | 131 | res.status(404) |