]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/handlers/video-channel-import.ts
Add expect message to ease debug
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / video-channel-import.ts
index 9bdb2d269b8ddf10090100916c3a53aa198b629b..035f88e96c00630f2ab374003e5103a8a84687d5 100644 (file)
@@ -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,30 @@ 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,
+    videosCountLimit: CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.FULL_SYNC_VIDEOS_LIMIT
+  })
 }