aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/index.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-31 11:52:52 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-10-31 11:53:13 +0100
commitfd45e8f43c2638478599ca75632518054461da85 (patch)
tree01e1fb5ddad53bde8fb2c48f348fb8add51cfdb3 /server/controllers/api/videos/index.ts
parentb7a485121d71c95fcf5e432e4cc745cf91af4f93 (diff)
downloadPeerTube-fd45e8f43c2638478599ca75632518054461da85.tar.gz
PeerTube-fd45e8f43c2638478599ca75632518054461da85.tar.zst
PeerTube-fd45e8f43c2638478599ca75632518054461da85.zip
Add video privacy setting
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r--server/controllers/api/videos/index.ts28
1 files changed, 23 insertions, 5 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 49f0e4630..4dd09917b 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -9,7 +9,8 @@ import {
9 REQUEST_VIDEO_EVENT_TYPES, 9 REQUEST_VIDEO_EVENT_TYPES,
10 VIDEO_CATEGORIES, 10 VIDEO_CATEGORIES,
11 VIDEO_LICENCES, 11 VIDEO_LICENCES,
12 VIDEO_LANGUAGES 12 VIDEO_LANGUAGES,
13 VIDEO_PRIVACIES
13} from '../../../initializers' 14} from '../../../initializers'
14import { 15import {
15 addEventToRemoteVideo, 16 addEventToRemoteVideo,
@@ -43,7 +44,7 @@ import {
43 resetSequelizeInstance 44 resetSequelizeInstance
44} from '../../../helpers' 45} from '../../../helpers'
45import { VideoInstance } from '../../../models' 46import { VideoInstance } from '../../../models'
46import { VideoCreate, VideoUpdate } from '../../../../shared' 47import { VideoCreate, VideoUpdate, VideoPrivacy } from '../../../../shared'
47 48
48import { abuseVideoRouter } from './abuse' 49import { abuseVideoRouter } from './abuse'
49import { blacklistRouter } from './blacklist' 50import { blacklistRouter } from './blacklist'
@@ -84,6 +85,7 @@ videosRouter.use('/', videoChannelRouter)
84videosRouter.get('/categories', listVideoCategories) 85videosRouter.get('/categories', listVideoCategories)
85videosRouter.get('/licences', listVideoLicences) 86videosRouter.get('/licences', listVideoLicences)
86videosRouter.get('/languages', listVideoLanguages) 87videosRouter.get('/languages', listVideoLanguages)
88videosRouter.get('/privacies', listVideoPrivacies)
87 89
88videosRouter.get('/', 90videosRouter.get('/',
89 paginationValidator, 91 paginationValidator,
@@ -149,6 +151,10 @@ function listVideoLanguages (req: express.Request, res: express.Response) {
149 res.json(VIDEO_LANGUAGES) 151 res.json(VIDEO_LANGUAGES)
150} 152}
151 153
154function listVideoPrivacies (req: express.Request, res: express.Response) {
155 res.json(VIDEO_PRIVACIES)
156}
157
152// Wrapper to video add that retry the function if there is a database error 158// Wrapper to video add that retry the function if there is a database error
153// We need this because we run the transaction in SERIALIZABLE isolation that can fail 159// We need this because we run the transaction in SERIALIZABLE isolation that can fail
154async function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { 160async function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -179,6 +185,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
179 language: videoInfo.language, 185 language: videoInfo.language,
180 nsfw: videoInfo.nsfw, 186 nsfw: videoInfo.nsfw,
181 description: videoInfo.description, 187 description: videoInfo.description,
188 privacy: videoInfo.privacy,
182 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware 189 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
183 channelId: res.locals.videoChannel.id 190 channelId: res.locals.videoChannel.id
184 } 191 }
@@ -240,6 +247,8 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
240 247
241 // Let transcoding job send the video to friends because the video file extension might change 248 // Let transcoding job send the video to friends because the video file extension might change
242 if (CONFIG.TRANSCODING.ENABLED === true) return undefined 249 if (CONFIG.TRANSCODING.ENABLED === true) return undefined
250 // Don't send video to remote pods, it is private
251 if (video.privacy === VideoPrivacy.PRIVATE) return undefined
243 252
244 const remoteVideo = await video.toAddRemoteJSON() 253 const remoteVideo = await video.toAddRemoteJSON()
245 // Now we'll add the video's meta data to our friends 254 // Now we'll add the video's meta data to our friends
@@ -264,6 +273,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
264 const videoInstance = res.locals.video 273 const videoInstance = res.locals.video
265 const videoFieldsSave = videoInstance.toJSON() 274 const videoFieldsSave = videoInstance.toJSON()
266 const videoInfoToUpdate: VideoUpdate = req.body 275 const videoInfoToUpdate: VideoUpdate = req.body
276 const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE
267 277
268 try { 278 try {
269 await db.sequelize.transaction(async t => { 279 await db.sequelize.transaction(async t => {
@@ -276,6 +286,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
276 if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence) 286 if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
277 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language) 287 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
278 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw) 288 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
289 if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', videoInfoToUpdate.privacy)
279 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) 290 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
280 291
281 await videoInstance.save(sequelizeOptions) 292 await videoInstance.save(sequelizeOptions)
@@ -287,10 +298,17 @@ async function updateVideo (req: express.Request, res: express.Response) {
287 videoInstance.Tags = tagInstances 298 videoInstance.Tags = tagInstances
288 } 299 }
289 300
290 const json = videoInstance.toUpdateRemoteJSON()
291
292 // Now we'll update the video's meta data to our friends 301 // Now we'll update the video's meta data to our friends
293 return updateVideoToFriends(json, t) 302 if (wasPrivateVideo === false) {
303 const json = videoInstance.toUpdateRemoteJSON()
304 return updateVideoToFriends(json, t)
305 }
306
307 // Video is not private anymore, send a create action to remote pods
308 if (wasPrivateVideo === true && videoInstance.privacy !== VideoPrivacy.PRIVATE) {
309 const remoteVideo = await videoInstance.toAddRemoteJSON()
310 return addVideoToFriends(remoteVideo, t)
311 }
294 }) 312 })
295 313
296 logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid) 314 logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid)