1 import { Job } from 'bullmq'
2 import { logger } from '@server/helpers/logger'
3 import { CONFIG } from '@server/initializers/config'
4 import { synchronizeChannel } from '@server/lib/sync-channel'
5 import { VideoChannelModel } from '@server/models/video/video-channel'
6 import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
7 import { MChannelSync } from '@server/types/models'
8 import { VideoChannelImportPayload } from '@shared/models'
10 export async function processVideoChannelImport (job: Job) {
11 const payload = job.data as VideoChannelImportPayload
13 logger.info('Processing video channel import in job %s.', job.id)
15 // Channel import requires only http upload to be allowed
16 if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) {
17 throw new Error('Cannot import channel as the HTTP upload is disabled')
20 if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) {
21 throw new Error('Cannot import channel as the synchronization is disabled')
24 let channelSync: MChannelSync
25 if (payload.partOfChannelSyncId) {
26 channelSync = await VideoChannelSyncModel.loadWithChannel(payload.partOfChannelSyncId)
29 throw new Error('Unlnown channel sync specified in videos channel import')
33 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(payload.videoChannelId)
35 logger.info(`Starting importing videos from external channel "${payload.externalChannelUrl}" to "${videoChannel.name}" `)
37 await synchronizeChannel({
38 channel: videoChannel,
39 externalChannelUrl: payload.externalChannelUrl,