diff options
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 27 |
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 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { ActivityUpdate } from '../../../../shared/models/activitypub' | 2 | import { ActivityUpdate } from '../../../../shared/models/activitypub' |
3 | import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' | 3 | import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' |
4 | import { VideoTorrentObject } from '../../../../shared/models/activitypub/objects' | ||
5 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
6 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
7 | import { resetSequelizeInstance } from '../../../helpers/utils' | 6 | import { resetSequelizeInstance } from '../../../helpers/utils' |
@@ -13,6 +12,7 @@ import { VideoChannelModel } from '../../../models/video/video-channel' | |||
13 | import { VideoFileModel } from '../../../models/video/video-file' | 12 | import { VideoFileModel } from '../../../models/video/video-file' |
14 | import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' | 13 | import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' |
15 | import { | 14 | import { |
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 | ||
53 | async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) { | 53 | async 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) |