1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Add ability to update a video channel

This commit is contained in:
Chocobozzz 2018-05-11 15:10:13 +02:00
parent 9675333dec
commit 0f320037e6
No known key found for this signature in database
GPG key ID: 583A612D890159BE
26 changed files with 296 additions and 95 deletions

View file

@ -14,7 +14,7 @@ import { VideoFileModel } from '../../../models/video/video-file'
import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor'
import {
generateThumbnailFromUrl,
getOrCreateAccountAndVideoAndChannel,
getOrCreateAccountAndVideoAndChannel, getOrCreateVideoChannel,
videoActivityObjectToDBAttributes,
videoFileActivityUrlToDBAttributes
} from '../videos'
@ -54,6 +54,10 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
const res = await getOrCreateAccountAndVideoAndChannel(videoAttributesToUpdate.id)
// Fetch video channel outside the transaction
const newVideoChannelActor = await getOrCreateVideoChannel(videoAttributesToUpdate)
const newVideoChannel = newVideoChannelActor.VideoChannel
logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid)
let videoInstance = res.video
let videoFieldsSave: any
@ -66,12 +70,13 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
videoFieldsSave = videoInstance.toJSON()
// Check actor has the right to update the video
const videoChannel = videoInstance.VideoChannel
if (videoChannel.Account.Actor.id !== actor.id) {
throw new Error('Account ' + actor.url + ' does not own video channel ' + videoChannel.Actor.url)
}
const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoAttributesToUpdate, activity.to)
const videoData = await videoActivityObjectToDBAttributes(newVideoChannel, videoAttributesToUpdate, activity.to)
videoInstance.set('name', videoData.name)
videoInstance.set('uuid', videoData.uuid)
videoInstance.set('url', videoData.url)
@ -87,6 +92,7 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
videoInstance.set('updatedAt', videoData.updatedAt)
videoInstance.set('views', videoData.views)
videoInstance.set('privacy', videoData.privacy)
videoInstance.set('channelId', videoData.channelId)
await videoInstance.save(sequelizeOptions)