import { VideoModel } from '../../../models/video/video'
import { VideoCommentModel } from '../../../models/video/video-comment'
import { areValidationErrors } from '../utils'
+import { Hooks } from '../../../lib/plugins/hooks'
+import { isLocalVideoThreadAccepted, isLocalVideoCommentReplyAccepted, AcceptResult } from '../../../lib/moderation'
const listVideoCommentThreadsValidator = [
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
if (areValidationErrors(req, res)) return
if (!await doesVideoExist(req.params.videoId, res)) return
if (!isVideoCommentsEnabled(res.locals.video, res)) return
+ if (!await isVideoCommentAccepted(req, res, false)) return
return next()
}
if (!await doesVideoExist(req.params.videoId, res)) return
if (!isVideoCommentsEnabled(res.locals.video, res)) return
if (!await doesVideoCommentExist(req.params.commentId, res.locals.video, res)) return
+ if (!await isVideoCommentAccepted(req, res, true)) return
return next()
}
return true
}
+
+async function isVideoCommentAccepted (req: express.Request, res: express.Response, isReply: boolean) {
+ const acceptParameters = {
+ video: res.locals.video,
+ commentBody: req.body,
+ user: res.locals.oauth.token.User
+ }
+
+ let acceptedResult: AcceptResult
+
+ if (isReply) {
+ const acceptReplyParameters = Object.assign(acceptParameters, { parentComment: res.locals.videoComment })
+
+ acceptedResult = await Hooks.wrapObject(
+ isLocalVideoCommentReplyAccepted(acceptReplyParameters),
+ 'filter:api.video-comment-reply.create.accept.result'
+ )
+ } else {
+ acceptedResult = await Hooks.wrapObject(
+ isLocalVideoThreadAccepted(acceptParameters),
+ 'filter:api.video-thread.create.accept.result'
+ )
+ }
+
+ if (!acceptedResult || acceptedResult.accepted !== true) {
+ logger.info('Refused local comment.', { acceptedResult, acceptParameters })
+ res.status(403)
+ .json({ error: acceptedResult.errorMessage || 'Refused local comment' })
+
+ return false
+ }
+
+ return true
+}