1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
import { mergeMap } from 'rxjs'
import { SelectChannelItem } from 'src/types'
import { Component, OnInit } from '@angular/core'
import { Router } from '@angular/router'
import { AuthService, Notifier } from '@app/core'
import { listUserChannelsForSelect } from '@app/helpers'
import { VIDEO_CHANNEL_EXTERNAL_URL_VALIDATOR } from '@app/shared/form-validators/video-channel-validators'
import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
import { VideoChannelService, VideoChannelSyncService } from '@app/shared/shared-main'
import { VideoChannelSyncCreate } from '@shared/models/videos'
@Component({
selector: 'my-video-channel-sync-edit',
templateUrl: './video-channel-sync-edit.component.html',
styleUrls: [ './video-channel-sync-edit.component.scss' ]
})
export class VideoChannelSyncEditComponent extends FormReactive implements OnInit {
error: string
userVideoChannels: SelectChannelItem[] = []
existingVideosStrategy: string
constructor (
protected formValidatorService: FormValidatorService,
private authService: AuthService,
private router: Router,
private notifier: Notifier,
private videoChannelSyncService: VideoChannelSyncService,
private videoChannelService: VideoChannelService
) {
super()
}
ngOnInit () {
this.buildForm({
externalChannelUrl: VIDEO_CHANNEL_EXTERNAL_URL_VALIDATOR,
videoChannel: null,
existingVideoStrategy: null
})
listUserChannelsForSelect(this.authService)
.subscribe(channels => this.userVideoChannels = channels)
}
getFormButtonTitle () {
return $localize`Create`
}
formValidated () {
this.error = undefined
const body = this.form.value
const videoChannelSyncCreate: VideoChannelSyncCreate = {
externalChannelUrl: body.externalChannelUrl,
videoChannelId: body.videoChannel
}
const importExistingVideos = body['existingVideoStrategy'] === 'import'
this.videoChannelSyncService.createSync(videoChannelSyncCreate)
.pipe(mergeMap(({ videoChannelSync }) => {
return importExistingVideos
? this.videoChannelService.importVideos(videoChannelSync.channel.name, videoChannelSync.externalChannelUrl)
: Promise.resolve(null)
}))
.subscribe({
next: () => {
this.notifier.success($localize`Synchronization created successfully.`)
this.router.navigate([ '/my-library', 'video-channel-syncs' ])
},
error: err => {
this.error = err.message
}
})
}
}
|