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 { VideoChannelImportPayload } from '@shared/models'
8 export async function processVideoChannelImport (job: Job) {
9 const payload = job.data as VideoChannelImportPayload
11 logger.info('Processing video channel import in job %s.', job.id)
13 // Channel import requires only http upload to be allowed
14 if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) {
15 logger.error('Cannot import channel as the HTTP upload is disabled')
19 if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) {
20 logger.error('Cannot import channel as the synchronization is disabled')
24 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(payload.videoChannelId)
27 logger.info(`Starting importing videos from external channel "${payload.externalChannelUrl}" to "${videoChannel.name}" `)
29 await synchronizeChannel({
30 channel: videoChannel,
31 externalChannelUrl: payload.externalChannelUrl
34 logger.error(`Failed to import channel ${videoChannel.name}`, { err })