diff options
Diffstat (limited to 'server/controllers/api/videos/comment.ts')
-rw-r--r-- | server/controllers/api/videos/comment.ts | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index b11da2ef7..e09b242ed 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { ResultList } from '../../../../shared/models' | ||
2 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' | 3 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' |
3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { getFormattedObjects } from '../../../helpers/utils' | 5 | import { getFormattedObjects } from '../../../helpers/utils' |
@@ -10,6 +11,7 @@ import { | |||
10 | addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, | 11 | addVideoCommentReplyValidator, addVideoCommentThreadValidator, listVideoCommentThreadsValidator, |
11 | listVideoThreadCommentsValidator | 12 | listVideoThreadCommentsValidator |
12 | } from '../../../middlewares/validators/video-comments' | 13 | } from '../../../middlewares/validators/video-comments' |
14 | import { VideoModel } from '../../../models/video/video' | ||
13 | import { VideoCommentModel } from '../../../models/video/video-comment' | 15 | import { VideoCommentModel } from '../../../models/video/video-comment' |
14 | 16 | ||
15 | const videoCommentRouter = express.Router() | 17 | const videoCommentRouter = express.Router() |
@@ -47,13 +49,33 @@ export { | |||
47 | // --------------------------------------------------------------------------- | 49 | // --------------------------------------------------------------------------- |
48 | 50 | ||
49 | async function listVideoThreads (req: express.Request, res: express.Response, next: express.NextFunction) { | 51 | async function listVideoThreads (req: express.Request, res: express.Response, next: express.NextFunction) { |
50 | const resultList = await VideoCommentModel.listThreadsForApi(res.locals.video.id, req.query.start, req.query.count, req.query.sort) | 52 | const video = res.locals.video as VideoModel |
53 | let resultList: ResultList<VideoCommentModel> | ||
54 | |||
55 | if (video.commentsEnabled === true) { | ||
56 | resultList = await VideoCommentModel.listThreadsForApi(video.id, req.query.start, req.query.count, req.query.sort) | ||
57 | } else { | ||
58 | resultList = { | ||
59 | total: 0, | ||
60 | data: [] | ||
61 | } | ||
62 | } | ||
51 | 63 | ||
52 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 64 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
53 | } | 65 | } |
54 | 66 | ||
55 | async function listVideoThreadComments (req: express.Request, res: express.Response, next: express.NextFunction) { | 67 | async function listVideoThreadComments (req: express.Request, res: express.Response, next: express.NextFunction) { |
56 | const resultList = await VideoCommentModel.listThreadCommentsForApi(res.locals.video.id, res.locals.videoCommentThread.id) | 68 | const video = res.locals.video as VideoModel |
69 | let resultList: ResultList<VideoCommentModel> | ||
70 | |||
71 | if (video.commentsEnabled === true) { | ||
72 | resultList = await VideoCommentModel.listThreadCommentsForApi(res.locals.video.id, res.locals.videoCommentThread.id) | ||
73 | } else { | ||
74 | resultList = { | ||
75 | total: 0, | ||
76 | data: [] | ||
77 | } | ||
78 | } | ||
57 | 79 | ||
58 | return res.json(buildFormattedCommentTree(resultList)) | 80 | return res.json(buildFormattedCommentTree(resultList)) |
59 | } | 81 | } |