aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos/updater.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/videos/updater.ts')
-rw-r--r--server/lib/activitypub/videos/updater.ts47
1 files changed, 18 insertions, 29 deletions
diff --git a/server/lib/activitypub/videos/updater.ts b/server/lib/activitypub/videos/updater.ts
index 4338d1e22..11c177a68 100644
--- a/server/lib/activitypub/videos/updater.ts
+++ b/server/lib/activitypub/videos/updater.ts
@@ -7,17 +7,11 @@ import { PeerTubeSocket } from '@server/lib/peertube-socket'
7import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist' 7import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist'
8import { VideoCaptionModel } from '@server/models/video/video-caption' 8import { VideoCaptionModel } from '@server/models/video/video-caption'
9import { VideoLiveModel } from '@server/models/video/video-live' 9import { VideoLiveModel } from '@server/models/video/video-live'
10import { MChannelAccountLight, MChannelDefault, MVideoAccountLightBlacklistAllFiles, MVideoFullLight } from '@server/types/models' 10import { MActor, MChannelAccountLight, MChannelId, MVideoAccountLightBlacklistAllFiles, MVideoFullLight } from '@server/types/models'
11import { VideoObject, VideoPrivacy } from '@shared/models' 11import { VideoObject, VideoPrivacy } from '@shared/models'
12import { APVideoAbstractBuilder, getVideoAttributesFromObject } from './shared' 12import { APVideoAbstractBuilder, getVideoAttributesFromObject } from './shared'
13 13
14export class APVideoUpdater extends APVideoAbstractBuilder { 14export class APVideoUpdater extends APVideoAbstractBuilder {
15 protected readonly videoObject: VideoObject
16
17 private readonly video: MVideoAccountLightBlacklistAllFiles
18 private readonly channel: MChannelDefault
19 private readonly overrideTo: string[]
20
21 private readonly wasPrivateVideo: boolean 15 private readonly wasPrivateVideo: boolean
22 private readonly wasUnlistedVideo: boolean 16 private readonly wasUnlistedVideo: boolean
23 17
@@ -25,19 +19,12 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
25 19
26 private readonly oldVideoChannel: MChannelAccountLight 20 private readonly oldVideoChannel: MChannelAccountLight
27 21
28 constructor (options: { 22 constructor (
29 video: MVideoAccountLightBlacklistAllFiles 23 protected readonly videoObject: VideoObject,
30 videoObject: VideoObject 24 private readonly video: MVideoAccountLightBlacklistAllFiles
31 channel: MChannelDefault 25 ) {
32 overrideTo?: string[]
33 }) {
34 super() 26 super()
35 27
36 this.video = options.video
37 this.videoObject = options.videoObject
38 this.channel = options.channel
39 this.overrideTo = options.overrideTo
40
41 this.wasPrivateVideo = this.video.privacy === VideoPrivacy.PRIVATE 28 this.wasPrivateVideo = this.video.privacy === VideoPrivacy.PRIVATE
42 this.wasUnlistedVideo = this.video.privacy === VideoPrivacy.UNLISTED 29 this.wasUnlistedVideo = this.video.privacy === VideoPrivacy.UNLISTED
43 30
@@ -46,16 +33,18 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
46 this.videoFieldsSave = this.video.toJSON() 33 this.videoFieldsSave = this.video.toJSON()
47 } 34 }
48 35
49 async update () { 36 async update (overrideTo?: string[]) {
50 logger.debug('Updating remote video "%s".', this.videoObject.uuid, { videoObject: this.videoObject, channel: this.channel }) 37 logger.debug('Updating remote video "%s".', this.videoObject.uuid, { videoObject: this.videoObject })
51 38
52 try { 39 try {
40 const channelActor = await this.getOrCreateVideoChannelFromVideoObject()
41
53 const thumbnailModel = await this.tryToGenerateThumbnail(this.video) 42 const thumbnailModel = await this.tryToGenerateThumbnail(this.video)
54 43
55 const videoUpdated = await sequelizeTypescript.transaction(async t => { 44 const videoUpdated = await sequelizeTypescript.transaction(async t => {
56 this.checkChannelUpdateOrThrow() 45 this.checkChannelUpdateOrThrow(channelActor)
57 46
58 const videoUpdated = await this.updateVideo(t) 47 const videoUpdated = await this.updateVideo(channelActor.VideoChannel, t, overrideTo)
59 48
60 if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t) 49 if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t)
61 50
@@ -97,19 +86,19 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
97 } 86 }
98 87
99 // Check we can update the channel: we trust the remote server 88 // Check we can update the channel: we trust the remote server
100 private checkChannelUpdateOrThrow () { 89 private checkChannelUpdateOrThrow (newChannelActor: MActor) {
101 if (!this.oldVideoChannel.Actor.serverId || !this.channel.Actor.serverId) { 90 if (!this.oldVideoChannel.Actor.serverId || !newChannelActor.serverId) {
102 throw new Error('Cannot check old channel/new channel validity because `serverId` is null') 91 throw new Error('Cannot check old channel/new channel validity because `serverId` is null')
103 } 92 }
104 93
105 if (this.oldVideoChannel.Actor.serverId !== this.channel.Actor.serverId) { 94 if (this.oldVideoChannel.Actor.serverId !== newChannelActor.serverId) {
106 throw new Error(`New channel ${this.channel.Actor.url} is not on the same server than new channel ${this.oldVideoChannel.Actor.url}`) 95 throw new Error(`New channel ${newChannelActor.url} is not on the same server than new channel ${this.oldVideoChannel.Actor.url}`)
107 } 96 }
108 } 97 }
109 98
110 private updateVideo (transaction: Transaction) { 99 private updateVideo (channel: MChannelId, transaction: Transaction, overrideTo?: string[]) {
111 const to = this.overrideTo || this.videoObject.to 100 const to = overrideTo || this.videoObject.to
112 const videoData = getVideoAttributesFromObject(this.channel, this.videoObject, to) 101 const videoData = getVideoAttributesFromObject(channel, this.videoObject, to)
113 this.video.name = videoData.name 102 this.video.name = videoData.name
114 this.video.uuid = videoData.uuid 103 this.video.uuid = videoData.uuid
115 this.video.url = videoData.url 104 this.video.url = videoData.url