aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos/fetch.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/videos/fetch.ts')
-rw-r--r--server/lib/activitypub/videos/fetch.ts44
1 files changed, 22 insertions, 22 deletions
diff --git a/server/lib/activitypub/videos/fetch.ts b/server/lib/activitypub/videos/fetch.ts
index fdcf4ee5c..5e7f8552b 100644
--- a/server/lib/activitypub/videos/fetch.ts
+++ b/server/lib/activitypub/videos/fetch.ts
@@ -1,20 +1,19 @@
1import { checkUrlsSameHost, getAPId } from "@server/helpers/activitypub" 1import { checkUrlsSameHost, getAPId } from '@server/helpers/activitypub'
2import { sanitizeAndCheckVideoTorrentObject } from "@server/helpers/custom-validators/activitypub/videos" 2import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos'
3import { retryTransactionWrapper } from "@server/helpers/database-utils" 3import { retryTransactionWrapper } from '@server/helpers/database-utils'
4import { logger } from "@server/helpers/logger" 4import { logger } from '@server/helpers/logger'
5import { doJSONRequest, PeerTubeRequestError } from "@server/helpers/requests" 5import { doJSONRequest, PeerTubeRequestError } from '@server/helpers/requests'
6import { fetchVideoByUrl, VideoFetchByUrlType } from "@server/helpers/video" 6import { fetchVideoByUrl, VideoFetchByUrlType } from '@server/helpers/video'
7import { REMOTE_SCHEME } from "@server/initializers/constants" 7import { REMOTE_SCHEME } from '@server/initializers/constants'
8import { ActorFollowScoreCache } from "@server/lib/files-cache" 8import { ActorFollowScoreCache } from '@server/lib/files-cache'
9import { JobQueue } from "@server/lib/job-queue" 9import { JobQueue } from '@server/lib/job-queue'
10import { VideoModel } from "@server/models/video/video" 10import { VideoModel } from '@server/models/video/video'
11import { MVideoAccountLight, MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from "@server/types/models" 11import { MVideoAccountLight, MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models'
12import { HttpStatusCode } from "@shared/core-utils" 12import { HttpStatusCode } from '@shared/core-utils'
13import { VideoObject } from "@shared/models" 13import { VideoObject } from '@shared/models'
14import { getOrCreateActorAndServerAndModel } from "../actor" 14import { getOrCreateActorAndServerAndModel } from '../actor'
15import { SyncParam, syncVideoExternalAttributes } from "./shared" 15import { APVideoCreator, SyncParam, syncVideoExternalAttributes } from './shared'
16import { createVideo } from "./shared/video-create" 16import { APVideoUpdater } from './updater'
17import { APVideoUpdater } from "./update"
18 17
19async function fetchRemoteVideo (videoUrl: string): Promise<{ statusCode: number, videoObject: VideoObject }> { 18async function fetchRemoteVideo (videoUrl: string): Promise<{ statusCode: number, videoObject: VideoObject }> {
20 logger.info('Fetching remote video %s.', videoUrl) 19 logger.info('Fetching remote video %s.', videoUrl)
@@ -115,16 +114,17 @@ async function getOrCreateVideoAndAccountAndChannel (
115 return { video: videoFromDatabase, created: false } 114 return { video: videoFromDatabase, created: false }
116 } 115 }
117 116
118 const { videoObject: fetchedVideo } = await fetchRemoteVideo(videoUrl) 117 const { videoObject } = await fetchRemoteVideo(videoUrl)
119 if (!fetchedVideo) throw new Error('Cannot fetch remote video with url: ' + videoUrl) 118 if (!videoObject) throw new Error('Cannot fetch remote video with url: ' + videoUrl)
120 119
121 const actor = await getOrCreateVideoChannelFromVideoObject(fetchedVideo) 120 const actor = await getOrCreateVideoChannelFromVideoObject(videoObject)
122 const videoChannel = actor.VideoChannel 121 const videoChannel = actor.VideoChannel
123 122
124 try { 123 try {
125 const { autoBlacklisted, videoCreated } = await retryTransactionWrapper(createVideo, fetchedVideo, videoChannel, syncParam.thumbnail) 124 const creator = new APVideoCreator({ videoObject, channel: videoChannel })
125 const { autoBlacklisted, videoCreated } = await retryTransactionWrapper(creator.create.bind(creator), syncParam.thumbnail)
126 126
127 await syncVideoExternalAttributes(videoCreated, fetchedVideo, syncParam) 127 await syncVideoExternalAttributes(videoCreated, videoObject, syncParam)
128 128
129 return { video: videoCreated, created: true, autoBlacklisted } 129 return { video: videoCreated, created: true, autoBlacklisted }
130 } catch (err) { 130 } catch (err) {