diff options
Diffstat (limited to 'server/lib/activitypub/videos/fetch.ts')
-rw-r--r-- | server/lib/activitypub/videos/fetch.ts | 44 |
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 @@ | |||
1 | import { checkUrlsSameHost, getAPId } from "@server/helpers/activitypub" | 1 | import { checkUrlsSameHost, getAPId } from '@server/helpers/activitypub' |
2 | import { sanitizeAndCheckVideoTorrentObject } from "@server/helpers/custom-validators/activitypub/videos" | 2 | import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos' |
3 | import { retryTransactionWrapper } from "@server/helpers/database-utils" | 3 | import { retryTransactionWrapper } from '@server/helpers/database-utils' |
4 | import { logger } from "@server/helpers/logger" | 4 | import { logger } from '@server/helpers/logger' |
5 | import { doJSONRequest, PeerTubeRequestError } from "@server/helpers/requests" | 5 | import { doJSONRequest, PeerTubeRequestError } from '@server/helpers/requests' |
6 | import { fetchVideoByUrl, VideoFetchByUrlType } from "@server/helpers/video" | 6 | import { fetchVideoByUrl, VideoFetchByUrlType } from '@server/helpers/video' |
7 | import { REMOTE_SCHEME } from "@server/initializers/constants" | 7 | import { REMOTE_SCHEME } from '@server/initializers/constants' |
8 | import { ActorFollowScoreCache } from "@server/lib/files-cache" | 8 | import { ActorFollowScoreCache } from '@server/lib/files-cache' |
9 | import { JobQueue } from "@server/lib/job-queue" | 9 | import { JobQueue } from '@server/lib/job-queue' |
10 | import { VideoModel } from "@server/models/video/video" | 10 | 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" | 14 | import { getOrCreateActorAndServerAndModel } from '../actor' |
15 | import { SyncParam, syncVideoExternalAttributes } from "./shared" | 15 | import { APVideoCreator, SyncParam, syncVideoExternalAttributes } from './shared' |
16 | import { createVideo } from "./shared/video-create" | 16 | import { APVideoUpdater } from './updater' |
17 | import { APVideoUpdater } from "./update" | ||
18 | 17 | ||
19 | async function fetchRemoteVideo (videoUrl: string): Promise<{ statusCode: number, videoObject: VideoObject }> { | 18 | async 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) { |