X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Findex.ts;h=35f0b3152934e97cdbda3e4c2fba5220e9ea3fab;hb=22a73cb879a5cc775d4bec3d72fa9c9cf52e5175;hp=337795541c309821291614944faa4dbf40825808;hpb=91fa7960f42cff3481465bece3389007fbc278d3;p=github%2FChocobozzz%2FPeerTube.git 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) { const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) const videoInfoToUpdate: VideoUpdate = req.body - const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE - const wasNotPrivateVideo = videoInstance.privacy !== VideoPrivacy.PRIVATE - const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED + const wasConfidentialVideo = videoInstance.isConfidential() + const hadPrivacyForFederation = videoInstance.hasPrivacyForFederation() // Process thumbnail or create it from the video const thumbnailModel = req.files && req.files['thumbnailfile'] @@ -359,17 +358,15 @@ async function updateVideo (req: express.Request, res: express.Response) { videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt) } + let isNewVideo = false if (videoInfoToUpdate.privacy !== undefined) { - const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) - videoInstance.privacy = newPrivacy + isNewVideo = videoInstance.isNewVideo(videoInfoToUpdate.privacy) - // The video was private, and is not anymore -> publish it - if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) { - videoInstance.publishedAt = new Date() - } + const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) + videoInstance.setPrivacy(newPrivacy) - // The video was not private, but now it is -> we need to unfederate it - if (wasNotPrivateVideo === true && newPrivacy === VideoPrivacy.PRIVATE) { + // Unfederate the video if the new privacy is not compatible with federation + if (hadPrivacyForFederation && !videoInstance.hasPrivacyForFederation()) { await VideoModel.sendDelete(videoInstance, { transaction: t }) } } @@ -392,7 +389,7 @@ async function updateVideo (req: express.Request, res: express.Response) { await videoInstanceUpdated.$set('VideoChannel', res.locals.videoChannel, { transaction: t }) videoInstanceUpdated.VideoChannel = res.locals.videoChannel - if (wasPrivateVideo === false) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t) + if (hadPrivacyForFederation === true) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t) } // Schedule an update in the future? @@ -414,7 +411,6 @@ async function updateVideo (req: express.Request, res: express.Response) { transaction: t }) - const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) auditLogger.update( @@ -427,7 +423,7 @@ async function updateVideo (req: express.Request, res: express.Response) { return videoInstanceUpdated }) - if (wasUnlistedVideo || wasPrivateVideo) { + if (wasConfidentialVideo) { Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) }