diff options
author | Chocobozzz <me@florianbigard.com> | 2019-06-06 16:44:02 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-06-06 16:44:02 +0200 |
commit | 46a6db245f50249246325090eeaffd165453a396 (patch) | |
tree | 7cb829b19c56433270d23f0ac81bed0691293c3e /server/controllers | |
parent | 60919831276e9c9e9900258bec82b6c31e9e5dd3 (diff) | |
download | PeerTube-46a6db245f50249246325090eeaffd165453a396.tar.gz PeerTube-46a6db245f50249246325090eeaffd165453a396.tar.zst PeerTube-46a6db245f50249246325090eeaffd165453a396.zip |
Add ability to set to private a public/unlisted video
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/videos/index.ts | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 99900ca4a..5ebd8fbc4 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -199,11 +199,10 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
199 | const video = new VideoModel(videoData) | 199 | const video = new VideoModel(videoData) |
200 | video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object | 200 | video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object |
201 | 201 | ||
202 | const videoFileData = { | 202 | const videoFile = new VideoFileModel({ |
203 | extname: extname(videoPhysicalFile.filename), | 203 | extname: extname(videoPhysicalFile.filename), |
204 | size: videoPhysicalFile.size | 204 | size: videoPhysicalFile.size |
205 | } | 205 | }) |
206 | const videoFile = new VideoFileModel(videoFileData) | ||
207 | 206 | ||
208 | if (videoFile.isAudio()) { | 207 | if (videoFile.isAudio()) { |
209 | videoFile.resolution = DEFAULT_AUDIO_RESOLUTION | 208 | videoFile.resolution = DEFAULT_AUDIO_RESOLUTION |
@@ -321,7 +320,9 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
321 | const videoFieldsSave = videoInstance.toJSON() | 320 | const videoFieldsSave = videoInstance.toJSON() |
322 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) | 321 | const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON()) |
323 | const videoInfoToUpdate: VideoUpdate = req.body | 322 | const videoInfoToUpdate: VideoUpdate = req.body |
323 | |||
324 | const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE | 324 | const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE |
325 | const wasNotPrivateVideo = videoInstance.privacy !== VideoPrivacy.PRIVATE | ||
325 | const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED | 326 | const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED |
326 | 327 | ||
327 | // Process thumbnail or create it from the video | 328 | // Process thumbnail or create it from the video |
@@ -357,9 +358,15 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
357 | const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) | 358 | const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) |
358 | videoInstance.privacy = newPrivacy | 359 | videoInstance.privacy = newPrivacy |
359 | 360 | ||
361 | // The video was private, and is not anymore -> publish it | ||
360 | if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) { | 362 | if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) { |
361 | videoInstance.publishedAt = new Date() | 363 | videoInstance.publishedAt = new Date() |
362 | } | 364 | } |
365 | |||
366 | // The video was not private, but now it is -> we need to unfederate it | ||
367 | if (wasNotPrivateVideo === true && newPrivacy === VideoPrivacy.PRIVATE) { | ||
368 | await VideoModel.sendDelete(videoInstance, { transaction: t }) | ||
369 | } | ||
363 | } | 370 | } |
364 | 371 | ||
365 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) | 372 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) |