aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/job-queue/handlers/video-channel-import.ts20
-rw-r--r--server/lib/schedulers/video-channel-sync-latest-scheduler.ts4
-rw-r--r--server/lib/sync-channel.ts7
-rw-r--r--server/lib/video-import.ts3
4 files changed, 24 insertions, 10 deletions
diff --git a/server/lib/job-queue/handlers/video-channel-import.ts b/server/lib/job-queue/handlers/video-channel-import.ts
index 9bdb2d269..9aaad659e 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'
3import { CONFIG } from '@server/initializers/config' 3import { CONFIG } from '@server/initializers/config'
4import { synchronizeChannel } from '@server/lib/sync-channel' 4import { synchronizeChannel } from '@server/lib/sync-channel'
5import { VideoChannelModel } from '@server/models/video/video-channel' 5import { VideoChannelModel } from '@server/models/video/video-channel'
6import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync'
7import { MChannelSync } from '@server/types/models'
6import { VideoChannelImportPayload } from '@shared/models' 8import { VideoChannelImportPayload } from '@shared/models'
7 9
8export async function processVideoChannelImport (job: Job) { 10export async function processVideoChannelImport (job: Job) {
@@ -12,13 +14,20 @@ export async function processVideoChannelImport (job: Job) {
12 14
13 // Channel import requires only http upload to be allowed 15 // Channel import requires only http upload to be allowed
14 if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) { 16 if (!CONFIG.IMPORT.VIDEOS.HTTP.ENABLED) {
15 logger.error('Cannot import channel as the HTTP upload is disabled') 17 throw new Error('Cannot import channel as the HTTP upload is disabled')
16 return
17 } 18 }
18 19
19 if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) { 20 if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) {
20 logger.error('Cannot import channel as the synchronization is disabled') 21 throw new Error('Cannot import channel as the synchronization is disabled')
21 return 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 }
22 } 31 }
23 32
24 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(payload.videoChannelId) 33 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(payload.videoChannelId)
@@ -28,7 +37,8 @@ export async function processVideoChannelImport (job: Job) {
28 37
29 await synchronizeChannel({ 38 await synchronizeChannel({
30 channel: videoChannel, 39 channel: videoChannel,
31 externalChannelUrl: payload.externalChannelUrl 40 externalChannelUrl: payload.externalChannelUrl,
41 channelSync
32 }) 42 })
33 } catch (err) { 43 } catch (err) {
34 logger.error(`Failed to import channel ${videoChannel.name}`, { err }) 44 logger.error(`Failed to import channel ${videoChannel.name}`, { err })
diff --git a/server/lib/schedulers/video-channel-sync-latest-scheduler.ts b/server/lib/schedulers/video-channel-sync-latest-scheduler.ts
index fd9a35299..491ddaa87 100644
--- a/server/lib/schedulers/video-channel-sync-latest-scheduler.ts
+++ b/server/lib/schedulers/video-channel-sync-latest-scheduler.ts
@@ -36,10 +36,6 @@ export class VideoChannelSyncLatestScheduler extends AbstractScheduler {
36 36
37 const onlyAfter = sync.lastSyncAt || sync.createdAt 37 const onlyAfter = sync.lastSyncAt || sync.createdAt
38 38
39 sync.state = VideoChannelSyncState.PROCESSING
40 sync.lastSyncAt = new Date()
41 await sync.save()
42
43 await synchronizeChannel({ 39 await synchronizeChannel({
44 channel, 40 channel,
45 externalChannelUrl: sync.externalChannelUrl, 41 externalChannelUrl: sync.externalChannelUrl,
diff --git a/server/lib/sync-channel.ts b/server/lib/sync-channel.ts
index 50f80e6f9..eb5ca1703 100644
--- a/server/lib/sync-channel.ts
+++ b/server/lib/sync-channel.ts
@@ -18,6 +18,12 @@ export async function synchronizeChannel (options: {
18}) { 18}) {
19 const { channel, externalChannelUrl, videosCountLimit, onlyAfter, channelSync } = options 19 const { channel, externalChannelUrl, videosCountLimit, onlyAfter, channelSync } = options
20 20
21 if (channelSync) {
22 channelSync.state = VideoChannelSyncState.PROCESSING
23 channelSync.lastSyncAt = new Date()
24 await channelSync.save()
25 }
26
21 const user = await UserModel.loadByChannelActorId(channel.actorId) 27 const user = await UserModel.loadByChannelActorId(channel.actorId)
22 const youtubeDL = new YoutubeDLWrapper( 28 const youtubeDL = new YoutubeDLWrapper(
23 externalChannelUrl, 29 externalChannelUrl,
@@ -70,6 +76,7 @@ export async function synchronizeChannel (options: {
70 children.push(job) 76 children.push(job)
71 } 77 }
72 78
79 // Will update the channel sync status
73 const parent: CreateJobArgument = { 80 const parent: CreateJobArgument = {
74 type: 'after-video-channel-import', 81 type: 'after-video-channel-import',
75 payload: { 82 payload: {
diff --git a/server/lib/video-import.ts b/server/lib/video-import.ts
index fb9306967..de95116aa 100644
--- a/server/lib/video-import.ts
+++ b/server/lib/video-import.ts
@@ -206,7 +206,8 @@ async function buildYoutubeDLImport (options: {
206 videoImportAttributes: { 206 videoImportAttributes: {
207 targetUrl, 207 targetUrl,
208 state: VideoImportState.PENDING, 208 state: VideoImportState.PENDING,
209 userId: user.id 209 userId: user.id,
210 videoChannelSyncId: channelSync?.id
210 } 211 }
211 }) 212 })
212 213