aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/videos/index.ts24
-rw-r--r--server/controllers/api/videos/ownership.ts4
2 files changed, 12 insertions, 16 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
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts
index abb34082e..41d7cdc43 100644
--- a/server/controllers/api/videos/ownership.ts
+++ b/server/controllers/api/videos/ownership.ts
@@ -12,7 +12,7 @@ import {
12 videosTerminateChangeOwnershipValidator 12 videosTerminateChangeOwnershipValidator
13} from '../../../middlewares' 13} from '../../../middlewares'
14import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership' 14import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership'
15import { VideoChangeOwnershipStatus, VideoPrivacy, VideoState } from '../../../../shared/models/videos' 15import { VideoChangeOwnershipStatus, VideoState } from '../../../../shared/models/videos'
16import { VideoChannelModel } from '../../../models/video/video-channel' 16import { VideoChannelModel } from '../../../models/video/video-channel'
17import { getFormattedObjects } from '../../../helpers/utils' 17import { getFormattedObjects } from '../../../helpers/utils'
18import { changeVideoChannelShare } from '../../../lib/activitypub' 18import { changeVideoChannelShare } from '../../../lib/activitypub'
@@ -111,7 +111,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) {
111 const targetVideoUpdated = await targetVideo.save({ transaction: t }) as MVideoFullLight 111 const targetVideoUpdated = await targetVideo.save({ transaction: t }) as MVideoFullLight
112 targetVideoUpdated.VideoChannel = channel 112 targetVideoUpdated.VideoChannel = channel
113 113
114 if (targetVideoUpdated.privacy !== VideoPrivacy.PRIVATE && targetVideoUpdated.state === VideoState.PUBLISHED) { 114 if (targetVideoUpdated.hasPrivacyForFederation() && targetVideoUpdated.state === VideoState.PUBLISHED) {
115 await changeVideoChannelShare(targetVideoUpdated, oldVideoChannel, t) 115 await changeVideoChannelShare(targetVideoUpdated, oldVideoChannel, t)
116 await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor) 116 await sendUpdateVideo(targetVideoUpdated, t, oldVideoChannel.Account.Actor)
117 } 117 }