aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-12 20:04:58 +0200
committerChocobozzz <me@florianbigard.com>2018-06-12 20:37:51 +0200
commit2186386cca113506791583cb07d6ccacba7af4e0 (patch)
tree3c214c0b5fbd64332624267fa6e51fd4a9cf6474 /server/lib/activitypub/process
parent6ccdf3a23ecec5ba2eeaf487fd1fafdc7606b4bf (diff)
downloadPeerTube-2186386cca113506791583cb07d6ccacba7af4e0.tar.gz
PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.tar.zst
PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.zip
Add concept of video state, and add ability to wait transcoding before
publishing a video
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r--server/lib/activitypub/process/process-update.ts27
1 files changed, 16 insertions, 11 deletions
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index 2750f48c3..77de8c155 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -1,7 +1,6 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { ActivityUpdate } from '../../../../shared/models/activitypub' 2import { ActivityUpdate } from '../../../../shared/models/activitypub'
3import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' 3import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor'
4import { VideoTorrentObject } from '../../../../shared/models/activitypub/objects'
5import { retryTransactionWrapper } from '../../../helpers/database-utils' 4import { retryTransactionWrapper } from '../../../helpers/database-utils'
6import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
7import { resetSequelizeInstance } from '../../../helpers/utils' 6import { resetSequelizeInstance } from '../../../helpers/utils'
@@ -13,6 +12,7 @@ import { VideoChannelModel } from '../../../models/video/video-channel'
13import { VideoFileModel } from '../../../models/video/video-file' 12import { VideoFileModel } from '../../../models/video/video-file'
14import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' 13import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor'
15import { 14import {
15 fetchRemoteVideo,
16 generateThumbnailFromUrl, 16 generateThumbnailFromUrl,
17 getOrCreateAccountAndVideoAndChannel, 17 getOrCreateAccountAndVideoAndChannel,
18 getOrCreateVideoChannel, 18 getOrCreateVideoChannel,
@@ -51,15 +51,18 @@ function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate) {
51} 51}
52 52
53async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) { 53async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
54 const videoAttributesToUpdate = activity.object as VideoTorrentObject 54 const videoUrl = activity.object.id
55 55
56 const res = await getOrCreateAccountAndVideoAndChannel(videoAttributesToUpdate.id) 56 const videoObject = await fetchRemoteVideo(videoUrl)
57 if (!videoObject) throw new Error('Cannot fetch remote video with url: ' + videoUrl)
58
59 const res = await getOrCreateAccountAndVideoAndChannel(videoObject.id)
57 60
58 // Fetch video channel outside the transaction 61 // Fetch video channel outside the transaction
59 const newVideoChannelActor = await getOrCreateVideoChannel(videoAttributesToUpdate) 62 const newVideoChannelActor = await getOrCreateVideoChannel(videoObject)
60 const newVideoChannel = newVideoChannelActor.VideoChannel 63 const newVideoChannel = newVideoChannelActor.VideoChannel
61 64
62 logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid) 65 logger.debug('Updating remote video "%s".', videoObject.uuid)
63 let videoInstance = res.video 66 let videoInstance = res.video
64 let videoFieldsSave: any 67 let videoFieldsSave: any
65 68
@@ -77,7 +80,7 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
77 throw new Error('Account ' + actor.url + ' does not own video channel ' + videoChannel.Actor.url) 80 throw new Error('Account ' + actor.url + ' does not own video channel ' + videoChannel.Actor.url)
78 } 81 }
79 82
80 const videoData = await videoActivityObjectToDBAttributes(newVideoChannel, videoAttributesToUpdate, activity.to) 83 const videoData = await videoActivityObjectToDBAttributes(newVideoChannel, videoObject, activity.to)
81 videoInstance.set('name', videoData.name) 84 videoInstance.set('name', videoData.name)
82 videoInstance.set('uuid', videoData.uuid) 85 videoInstance.set('uuid', videoData.uuid)
83 videoInstance.set('url', videoData.url) 86 videoInstance.set('url', videoData.url)
@@ -88,6 +91,8 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
88 videoInstance.set('support', videoData.support) 91 videoInstance.set('support', videoData.support)
89 videoInstance.set('nsfw', videoData.nsfw) 92 videoInstance.set('nsfw', videoData.nsfw)
90 videoInstance.set('commentsEnabled', videoData.commentsEnabled) 93 videoInstance.set('commentsEnabled', videoData.commentsEnabled)
94 videoInstance.set('waitTranscoding', videoData.waitTranscoding)
95 videoInstance.set('state', videoData.state)
91 videoInstance.set('duration', videoData.duration) 96 videoInstance.set('duration', videoData.duration)
92 videoInstance.set('createdAt', videoData.createdAt) 97 videoInstance.set('createdAt', videoData.createdAt)
93 videoInstance.set('updatedAt', videoData.updatedAt) 98 videoInstance.set('updatedAt', videoData.updatedAt)
@@ -98,8 +103,8 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
98 await videoInstance.save(sequelizeOptions) 103 await videoInstance.save(sequelizeOptions)
99 104
100 // Don't block on request 105 // Don't block on request
101 generateThumbnailFromUrl(videoInstance, videoAttributesToUpdate.icon) 106 generateThumbnailFromUrl(videoInstance, videoObject.icon)
102 .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoAttributesToUpdate.id, { err })) 107 .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoObject.id, { err }))
103 108
104 // Remove old video files 109 // Remove old video files
105 const videoFileDestroyTasks: Bluebird<void>[] = [] 110 const videoFileDestroyTasks: Bluebird<void>[] = []
@@ -108,16 +113,16 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
108 } 113 }
109 await Promise.all(videoFileDestroyTasks) 114 await Promise.all(videoFileDestroyTasks)
110 115
111 const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoInstance, videoAttributesToUpdate) 116 const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoInstance, videoObject)
112 const tasks = videoFileAttributes.map(f => VideoFileModel.create(f)) 117 const tasks = videoFileAttributes.map(f => VideoFileModel.create(f))
113 await Promise.all(tasks) 118 await Promise.all(tasks)
114 119
115 const tags = videoAttributesToUpdate.tag.map(t => t.name) 120 const tags = videoObject.tag.map(t => t.name)
116 const tagInstances = await TagModel.findOrCreateTags(tags, t) 121 const tagInstances = await TagModel.findOrCreateTags(tags, t)
117 await videoInstance.$set('Tags', tagInstances, sequelizeOptions) 122 await videoInstance.$set('Tags', tagInstances, sequelizeOptions)
118 }) 123 })
119 124
120 logger.info('Remote video with uuid %s updated', videoAttributesToUpdate.uuid) 125 logger.info('Remote video with uuid %s updated', videoObject.uuid)
121 } catch (err) { 126 } catch (err) {
122 if (videoInstance !== undefined && videoFieldsSave !== undefined) { 127 if (videoInstance !== undefined && videoFieldsSave !== undefined) {
123 resetSequelizeInstance(videoInstance, videoFieldsSave) 128 resetSequelizeInstance(videoInstance, videoFieldsSave)