X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Fvideo-channel-import.ts;h=c3dd8a6888ecd52ac0ff1e8639c1483fa53faaaa;hb=cea2fd90ddb3bf57c2fed77128938d12d4c2be6b;hp=9bdb2d269b8ddf10090100916c3a53aa198b629b;hpb=2a491182e483b97afb1b65c908b23cb48d591807;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/job-queue/handlers/video-channel-import.ts b/server/lib/job-queue/handlers/video-channel-import.ts index 9bdb2d269..c3dd8a688 100644 --- a/server/lib/job-queue/handlers/video-channel-import.ts +++ b/server/lib/job-queue/handlers/video-channel-import.ts @@ -3,6 +3,8 @@ import { logger } from '@server/helpers/logger' import { CONFIG } from '@server/initializers/config' import { synchronizeChannel } from '@server/lib/sync-channel' import { VideoChannelModel } from '@server/models/video/video-channel' +import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync' +import { MChannelSync } from '@server/types/models' import { VideoChannelImportPayload } from '@shared/models' export async function processVideoChannelImport (job: Job) { @@ -12,25 +14,29 @@ export async function processVideoChannelImport (job: Job) { // Channel import requires only http upload to be allowed if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) { - logger.error('Cannot import channel as the HTTP upload is disabled') - return + throw new Error('Cannot import channel as the HTTP upload is disabled') } if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) { - logger.error('Cannot import channel as the synchronization is disabled') - return + throw new Error('Cannot import channel as the synchronization is disabled') + } + + let channelSync: MChannelSync + if (payload.partOfChannelSyncId) { + channelSync = await VideoChannelSyncModel.loadWithChannel(payload.partOfChannelSyncId) + + if (!channelSync) { + throw new Error('Unlnown channel sync specified in videos channel import') + } } const videoChannel = await VideoChannelModel.loadAndPopulateAccount(payload.videoChannelId) - try { - logger.info(`Starting importing videos from external channel "${payload.externalChannelUrl}" to "${videoChannel.name}" `) + logger.info(`Starting importing videos from external channel "${payload.externalChannelUrl}" to "${videoChannel.name}" `) - await synchronizeChannel({ - channel: videoChannel, - externalChannelUrl: payload.externalChannelUrl - }) - } catch (err) { - logger.error(`Failed to import channel ${videoChannel.name}`, { err }) - } + await synchronizeChannel({ + channel: videoChannel, + externalChannelUrl: payload.externalChannelUrl, + channelSync + }) }