aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/index.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-11 15:10:13 +0200
committerChocobozzz <me@florianbigard.com>2018-05-11 15:25:51 +0200
commit0f320037e689b2778959c12ddd4ce790f6e4ae4f (patch)
tree425acaa4345442388901c833275bb76b42a8a268 /server/controllers/api/videos/index.ts
parent9675333decd0b89b73a4fc67b39272f7296bfe3f (diff)
downloadPeerTube-0f320037e689b2778959c12ddd4ce790f6e4ae4f.tar.gz
PeerTube-0f320037e689b2778959c12ddd4ce790f6e4ae4f.tar.zst
PeerTube-0f320037e689b2778959c12ddd4ce790f6e4ae4f.zip
Add ability to update a video channel
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r--server/controllers/api/videos/index.ts25
1 files changed, 19 insertions, 6 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 4b3198a74..c07430e6c 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -19,7 +19,12 @@ import {
19 VIDEO_MIMETYPE_EXT, 19 VIDEO_MIMETYPE_EXT,
20 VIDEO_PRIVACIES 20 VIDEO_PRIVACIES
21} from '../../../initializers' 21} from '../../../initializers'
22import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' 22import {
23 changeVideoChannelShare,
24 fetchRemoteVideoDescription,
25 getVideoActivityPubUrl,
26 shareVideoByServerAndChannel
27} from '../../../lib/activitypub'
23import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send' 28import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send'
24import { JobQueue } from '../../../lib/job-queue' 29import { JobQueue } from '../../../lib/job-queue'
25import { Redis } from '../../../lib/redis' 30import { Redis } from '../../../lib/redis'
@@ -305,6 +310,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
305 const sequelizeOptions = { 310 const sequelizeOptions = {
306 transaction: t 311 transaction: t
307 } 312 }
313 const oldVideoChannel = videoInstance.VideoChannel
308 314
309 if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name) 315 if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name)
310 if (videoInfoToUpdate.category !== undefined) videoInstance.set('category', videoInfoToUpdate.category) 316 if (videoInfoToUpdate.category !== undefined) videoInstance.set('category', videoInfoToUpdate.category)
@@ -325,18 +331,25 @@ async function updateVideo (req: express.Request, res: express.Response) {
325 331
326 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) 332 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
327 333
334 // Video tags update?
328 if (videoInfoToUpdate.tags) { 335 if (videoInfoToUpdate.tags) {
329 const tagInstances = await TagModel.findOrCreateTags(videoInfoToUpdate.tags, t) 336 const tagInstances = await TagModel.findOrCreateTags(videoInfoToUpdate.tags, t)
330 337
331 await videoInstance.$set('Tags', tagInstances, sequelizeOptions) 338 await videoInstanceUpdated.$set('Tags', tagInstances, sequelizeOptions)
332 videoInstance.Tags = tagInstances 339 videoInstanceUpdated.Tags = tagInstances
333 } 340 }
334 341
335 // Now we'll update the video's meta data to our friends 342 // Video channel update?
336 if (wasPrivateVideo === false) { 343 if (res.locals.videoChannel && videoInstanceUpdated.channelId !== res.locals.videoChannel.id) {
337 await sendUpdateVideo(videoInstanceUpdated, t) 344 await videoInstanceUpdated.$set('VideoChannel', res.locals.videoChannel)
345 videoInstance.VideoChannel = res.locals.videoChannel
346
347 if (wasPrivateVideo === false) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t)
338 } 348 }
339 349
350 // Now we'll update the video's meta data to our friends
351 if (wasPrivateVideo === false) await sendUpdateVideo(videoInstanceUpdated, t)
352
340 // Video is not private anymore, send a create action to remote servers 353 // Video is not private anymore, send a create action to remote servers
341 if (wasPrivateVideo === true && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE) { 354 if (wasPrivateVideo === true && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE) {
342 await sendCreateVideo(videoInstanceUpdated, t) 355 await sendCreateVideo(videoInstanceUpdated, t)