diff options
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/comment.ts | 31 |
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' | |||
2 | import { ResultList } from '../../../../shared/models' | 2 | import { ResultList } from '../../../../shared/models' |
3 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' | 3 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' |
4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
5 | import { logger } from '../../../helpers/logger' | ||
5 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { getFormattedObjects } from '../../../helpers/utils' |
6 | import { sequelizeTypescript } from '../../../initializers' | 7 | import { sequelizeTypescript } from '../../../initializers' |
7 | import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' | 8 | import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' |
8 | import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares' | 9 | import { asyncMiddleware, authenticate, paginationValidator, setPagination, setVideoCommentThreadsSort } from '../../../middlewares' |
9 | import { videoCommentThreadsSortValidator } from '../../../middlewares/validators' | 10 | import { videoCommentThreadsSortValidator } from '../../../middlewares/validators' |
10 | import { | 11 | import { |
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' |
14 | import { VideoModel } from '../../../models/video/video' | 15 | import { VideoModel } from '../../../models/video/video' |
15 | import { VideoCommentModel } from '../../../models/video/video-comment' | 16 | import { 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 | ) |
43 | videoCommentRouter.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 | |||
141 | async 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 | |||
152 | async 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 | } | ||