diff options
Diffstat (limited to 'server/lib/activitypub/videos/fetch.ts')
-rw-r--r-- | server/lib/activitypub/videos/fetch.ts | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/server/lib/activitypub/videos/fetch.ts b/server/lib/activitypub/videos/fetch.ts index 5e7f8552b..5113c9d7e 100644 --- a/server/lib/activitypub/videos/fetch.ts +++ b/server/lib/activitypub/videos/fetch.ts | |||
@@ -11,7 +11,6 @@ import { VideoModel } from '@server/models/video/video' | |||
11 | import { MVideoAccountLight, MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models' | 11 | import { MVideoAccountLight, MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models' |
12 | import { HttpStatusCode } from '@shared/core-utils' | 12 | import { HttpStatusCode } from '@shared/core-utils' |
13 | import { VideoObject } from '@shared/models' | 13 | import { VideoObject } from '@shared/models' |
14 | import { getOrCreateActorAndServerAndModel } from '../actor' | ||
15 | import { APVideoCreator, SyncParam, syncVideoExternalAttributes } from './shared' | 14 | import { APVideoCreator, SyncParam, syncVideoExternalAttributes } from './shared' |
16 | import { APVideoUpdater } from './updater' | 15 | import { APVideoUpdater } from './updater' |
17 | 16 | ||
@@ -37,17 +36,6 @@ async function fetchRemoteVideoDescription (video: MVideoAccountLight) { | |||
37 | return body.description || '' | 36 | return body.description || '' |
38 | } | 37 | } |
39 | 38 | ||
40 | function getOrCreateVideoChannelFromVideoObject (videoObject: VideoObject) { | ||
41 | const channel = videoObject.attributedTo.find(a => a.type === 'Group') | ||
42 | if (!channel) throw new Error('Cannot find associated video channel to video ' + videoObject.url) | ||
43 | |||
44 | if (checkUrlsSameHost(channel.id, videoObject.id) !== true) { | ||
45 | throw new Error(`Video channel url ${channel.id} does not have the same host than video object id ${videoObject.id}`) | ||
46 | } | ||
47 | |||
48 | return getOrCreateActorAndServerAndModel(channel.id, 'all') | ||
49 | } | ||
50 | |||
51 | type GetVideoResult <T> = Promise<{ | 39 | type GetVideoResult <T> = Promise<{ |
52 | video: T | 40 | video: T |
53 | created: boolean | 41 | created: boolean |
@@ -117,11 +105,8 @@ async function getOrCreateVideoAndAccountAndChannel ( | |||
117 | const { videoObject } = await fetchRemoteVideo(videoUrl) | 105 | const { videoObject } = await fetchRemoteVideo(videoUrl) |
118 | if (!videoObject) throw new Error('Cannot fetch remote video with url: ' + videoUrl) | 106 | if (!videoObject) throw new Error('Cannot fetch remote video with url: ' + videoUrl) |
119 | 107 | ||
120 | const actor = await getOrCreateVideoChannelFromVideoObject(videoObject) | ||
121 | const videoChannel = actor.VideoChannel | ||
122 | |||
123 | try { | 108 | try { |
124 | const creator = new APVideoCreator({ videoObject, channel: videoChannel }) | 109 | const creator = new APVideoCreator(videoObject) |
125 | const { autoBlacklisted, videoCreated } = await retryTransactionWrapper(creator.create.bind(creator), syncParam.thumbnail) | 110 | const { autoBlacklisted, videoCreated } = await retryTransactionWrapper(creator.create.bind(creator), syncParam.thumbnail) |
126 | 111 | ||
127 | await syncVideoExternalAttributes(videoCreated, videoObject, syncParam) | 112 | await syncVideoExternalAttributes(videoCreated, videoObject, syncParam) |
@@ -160,13 +145,7 @@ async function refreshVideoIfNeeded (options: { | |||
160 | return video | 145 | return video |
161 | } | 146 | } |
162 | 147 | ||
163 | const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject) | 148 | const videoUpdater = new APVideoUpdater(videoObject, video) |
164 | |||
165 | const videoUpdater = new APVideoUpdater({ | ||
166 | video, | ||
167 | videoObject, | ||
168 | channel: channelActor.VideoChannel | ||
169 | }) | ||
170 | await videoUpdater.update() | 149 | await videoUpdater.update() |
171 | 150 | ||
172 | await syncVideoExternalAttributes(video, videoObject, options.syncParam) | 151 | await syncVideoExternalAttributes(video, videoObject, options.syncParam) |
@@ -197,6 +176,5 @@ export { | |||
197 | fetchRemoteVideo, | 176 | fetchRemoteVideo, |
198 | fetchRemoteVideoDescription, | 177 | fetchRemoteVideoDescription, |
199 | refreshVideoIfNeeded, | 178 | refreshVideoIfNeeded, |
200 | getOrCreateVideoChannelFromVideoObject, | ||
201 | getOrCreateVideoAndAccountAndChannel | 179 | getOrCreateVideoAndAccountAndChannel |
202 | } | 180 | } |