]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/job-queue/handlers/video-channel-import.ts
Merge branch 'release/5.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / video-channel-import.ts
CommitLineData
2a491182
F
1import { Job } from 'bullmq'
2import { logger } from '@server/helpers/logger'
3import { CONFIG } from '@server/initializers/config'
4import { synchronizeChannel } from '@server/lib/sync-channel'
5import { VideoChannelModel } from '@server/models/video/video-channel'
a3b472a1
C
6import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
7import { MChannelSync } from '@server/types/models'
97922ecf 8import { VideoChannelImportPayload } from '@shared/models'
2a491182
F
9
10export async function processVideoChannelImport (job: Job) {
11 const payload = job.data as VideoChannelImportPayload
12
13 logger.info('Processing video channel import in job %s.', job.id)
14
15 // Channel import requires only http upload to be allowed
16 if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) {
a3b472a1 17 throw new Error('Cannot import channel as the HTTP upload is disabled')
2a491182
F
18 }
19
20 if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) {
a3b472a1
C
21 throw new Error('Cannot import channel as the synchronization is disabled')
22 }
23
24 let channelSync: MChannelSync
25 if (payload.partOfChannelSyncId) {
26 channelSync = await VideoChannelSyncModel.loadWithChannel(payload.partOfChannelSyncId)
27
28 if (!channelSync) {
29 throw new Error('Unlnown channel sync specified in videos channel import')
30 }
2a491182
F
31 }
32
33 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(payload.videoChannelId)
34
97922ecf
C
35 logger.info(`Starting importing videos from external channel "${payload.externalChannelUrl}" to "${videoChannel.name}" `)
36
37 await synchronizeChannel({
38 channel: videoChannel,
39 externalChannelUrl: payload.externalChannelUrl,
4efa5535
C
40 channelSync,
41 videosCountLimit: CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.FULL_SYNC_VIDEOS_LIMIT
97922ecf 42 })
2a491182 43}