aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-03 10:12:36 +0100
committerChocobozzz <me@florianbigard.com>2018-01-03 10:38:19 +0100
commit47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04 (patch)
tree25e2836baf3dfce6f422192d98332db1bfe65890 /server/controllers/api
parentc5911fd347c76e8bdc05ea9f3ee9efed4a58c236 (diff)
downloadPeerTube-47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04.tar.gz
PeerTube-47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04.tar.zst
PeerTube-47564bbe2eeb2baae9b7e3f9b2b8d16522bc7e04.zip
Add ability to disable video comments
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/videos/comment.ts26
-rw-r--r--server/controllers/api/videos/index.ts5
2 files changed, 27 insertions, 4 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { ResultList } from '../../../../shared/models'
2import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' 3import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
3import { retryTransactionWrapper } from '../../../helpers/database-utils' 4import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { getFormattedObjects } from '../../../helpers/utils' 5import { 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'
14import { VideoModel } from '../../../models/video/video'
13import { VideoCommentModel } from '../../../models/video/video-comment' 15import { VideoCommentModel } from '../../../models/video/video-comment'
14 16
15const videoCommentRouter = express.Router() 17const videoCommentRouter = express.Router()
@@ -47,13 +49,33 @@ export {
47// --------------------------------------------------------------------------- 49// ---------------------------------------------------------------------------
48 50
49async function listVideoThreads (req: express.Request, res: express.Response, next: express.NextFunction) { 51async 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
55async function listVideoThreadComments (req: express.Request, res: express.Response, next: express.NextFunction) { 67async 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}
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index ff0d967e1..368327914 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -1,12 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as multer from 'multer'
3import { extname, join } from 'path' 2import { extname, join } from 'path'
4import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared' 3import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared'
5import { renamePromise } from '../../../helpers/core-utils' 4import { renamePromise } from '../../../helpers/core-utils'
6import { retryTransactionWrapper } from '../../../helpers/database-utils' 5import { retryTransactionWrapper } from '../../../helpers/database-utils'
7import { getVideoFileHeight } from '../../../helpers/ffmpeg-utils' 6import { getVideoFileHeight } from '../../../helpers/ffmpeg-utils'
8import { logger } from '../../../helpers/logger' 7import { logger } from '../../../helpers/logger'
9import { createReqFiles, generateRandomString, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils' 8import { createReqFiles, getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils'
10import { 9import {
11 CONFIG, sequelizeTypescript, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, 10 CONFIG, sequelizeTypescript, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT,
12 VIDEO_PRIVACIES 11 VIDEO_PRIVACIES
@@ -141,6 +140,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
141 category: videoInfo.category, 140 category: videoInfo.category,
142 licence: videoInfo.licence, 141 licence: videoInfo.licence,
143 language: videoInfo.language, 142 language: videoInfo.language,
143 commentsEnabled: videoInfo.commentsEnabled,
144 nsfw: videoInfo.nsfw, 144 nsfw: videoInfo.nsfw,
145 description: videoInfo.description, 145 description: videoInfo.description,
146 privacy: videoInfo.privacy, 146 privacy: videoInfo.privacy,
@@ -248,6 +248,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
248 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw) 248 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
249 if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', parseInt(videoInfoToUpdate.privacy.toString(), 10)) 249 if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', parseInt(videoInfoToUpdate.privacy.toString(), 10))
250 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) 250 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
251 if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled)
251 252
252 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) 253 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
253 254