aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/comment.ts31
1 files changed, 29 insertions, 2 deletions
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index e09b242ed..65fcf6b35 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -2,14 +2,15 @@ import * as express from 'express'
2import { ResultList } from '../../../../shared/models' 2import { ResultList } from '../../../../shared/models'
3import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' 3import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
4import { retryTransactionWrapper } from '../../../helpers/database-utils' 4import { retryTransactionWrapper } from '../../../helpers/database-utils'
5import { logger } from '../../../helpers/logger'
5import { getFormattedObjects } from '../../../helpers/utils' 6import { getFormattedObjects } from '../../../helpers/utils'
6import { sequelizeTypescript } from '../../../initializers' 7import { sequelizeTypescript } from '../../../initializers'
7import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' 8import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment'
8import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares' 9import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares'
9import { videoCommentThreadsSortValidator } from '../../../middlewares/validators' 10import { videoCommentThreadsSortValidator } from '../../../middlewares/validators'
10import { 11import {
11 addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, 12 addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, listVideoThreadCommentsValidator,
12 listVideoThreadCommentsValidator 13 removeVideoCommentValidator
13} from '../../../middlewares/validators/video-comments' 14} from '../../../middlewares/validators/video-comments'
14import { VideoModel } from '../../../models/video/video' 15import { VideoModel } from '../../../models/video/video'
15import { VideoCommentModel } from '../../../models/video/video-comment' 16import { VideoCommentModel } from '../../../models/video/video-comment'
@@ -39,6 +40,11 @@ videoCommentRouter.post('/:videoId/comments/:commentId',
39 asyncMiddleware(addVideoCommentReplyValidator), 40 asyncMiddleware(addVideoCommentReplyValidator),
40 asyncMiddleware(addVideoCommentReplyRetryWrapper) 41 asyncMiddleware(addVideoCommentReplyRetryWrapper)
41) 42)
43videoCommentRouter.delete('/:videoId/comments/:commentId',
44 authenticate,
45 asyncMiddleware(removeVideoCommentValidator),
46 asyncMiddleware(removeVideoCommentRetryWrapper)
47)
42 48
43// --------------------------------------------------------------------------- 49// ---------------------------------------------------------------------------
44 50
@@ -131,3 +137,24 @@ function addVideoCommentReply (req: express.Request, res: express.Response, next
131 }, t) 137 }, t)
132 }) 138 })
133} 139}
140
141async function removeVideoCommentRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
142 const options = {
143 arguments: [ req, res ],
144 errorMessage: 'Cannot remove the video comment with many retries.'
145 }
146
147 await retryTransactionWrapper(removeVideoComment, options)
148
149 return res.type('json').status(204).end()
150}
151
152async function removeVideoComment (req: express.Request, res: express.Response) {
153 const videoCommentInstance: VideoCommentModel = res.locals.videoComment
154
155 await sequelizeTypescript.transaction(async t => {
156 await videoCommentInstance.destroy({ transaction: t })
157 })
158
159 logger.info('Video comment %d deleted.', videoCommentInstance.id)
160}