aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/index.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-12-12 15:47:47 +0100
committerChocobozzz <me@florianbigard.com>2019-12-12 16:51:59 +0100
commit22a73cb879a5cc775d4bec3d72fa9c9cf52e5175 (patch)
tree4c8d2d4f6fce8a520420ec83722fefc6d57b7a83 /server/controllers/api/videos/index.ts
parent91fa7960f42cff3481465bece3389007fbc278d3 (diff)
downloadPeerTube-22a73cb879a5cc775d4bec3d72fa9c9cf52e5175.tar.gz
PeerTube-22a73cb879a5cc775d4bec3d72fa9c9cf52e5175.tar.zst
PeerTube-22a73cb879a5cc775d4bec3d72fa9c9cf52e5175.zip
Add internal privacy mode
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r--server/controllers/api/videos/index.ts24
1 files changed, 10 insertions, 14 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 337795541..35f0b3152 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -326,9 +326,8 @@ async function updateVideo (req: express.Request, res: express.Response) {
326 const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) 326 const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON())
327 const videoInfoToUpdate: VideoUpdate = req.body 327 const videoInfoToUpdate: VideoUpdate = req.body
328 328
329 const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE 329 const wasConfidentialVideo = videoInstance.isConfidential()
330 const wasNotPrivateVideo = videoInstance.privacy !== VideoPrivacy.PRIVATE 330 const hadPrivacyForFederation = videoInstance.hasPrivacyForFederation()
331 const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED
332 331
333 // Process thumbnail or create it from the video 332 // Process thumbnail or create it from the video
334 const thumbnailModel = req.files && req.files['thumbnailfile'] 333 const thumbnailModel = req.files && req.files['thumbnailfile']
@@ -359,17 +358,15 @@ async function updateVideo (req: express.Request, res: express.Response) {
359 videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt) 358 videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt)
360 } 359 }
361 360
361 let isNewVideo = false
362 if (videoInfoToUpdate.privacy !== undefined) { 362 if (videoInfoToUpdate.privacy !== undefined) {
363 const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) 363 isNewVideo = videoInstance.isNewVideo(videoInfoToUpdate.privacy)
364 videoInstance.privacy = newPrivacy
365 364
366 // The video was private, and is not anymore -> publish it 365 const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
367 if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) { 366 videoInstance.setPrivacy(newPrivacy)
368 videoInstance.publishedAt = new Date()
369 }
370 367
371 // The video was not private, but now it is -> we need to unfederate it 368 // Unfederate the video if the new privacy is not compatible with federation
372 if (wasNotPrivateVideo === true && newPrivacy === VideoPrivacy.PRIVATE) { 369 if (hadPrivacyForFederation && !videoInstance.hasPrivacyForFederation()) {
373 await VideoModel.sendDelete(videoInstance, { transaction: t }) 370 await VideoModel.sendDelete(videoInstance, { transaction: t })
374 } 371 }
375 } 372 }
@@ -392,7 +389,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
392 await videoInstanceUpdated.$set('VideoChannel', res.locals.videoChannel, { transaction: t }) 389 await videoInstanceUpdated.$set('VideoChannel', res.locals.videoChannel, { transaction: t })
393 videoInstanceUpdated.VideoChannel = res.locals.videoChannel 390 videoInstanceUpdated.VideoChannel = res.locals.videoChannel
394 391
395 if (wasPrivateVideo === false) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t) 392 if (hadPrivacyForFederation === true) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t)
396 } 393 }
397 394
398 // Schedule an update in the future? 395 // Schedule an update in the future?
@@ -414,7 +411,6 @@ async function updateVideo (req: express.Request, res: express.Response) {
414 transaction: t 411 transaction: t
415 }) 412 })
416 413
417 const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
418 await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) 414 await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
419 415
420 auditLogger.update( 416 auditLogger.update(
@@ -427,7 +423,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
427 return videoInstanceUpdated 423 return videoInstanceUpdated
428 }) 424 })
429 425
430 if (wasUnlistedVideo || wasPrivateVideo) { 426 if (wasConfidentialVideo) {
431 Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) 427 Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
432 } 428 }
433 429