PeerTube/client/src/app/+videos/+video-edit/video-add-components/video-send.ts

105 lines
3.3 KiB
TypeScript
Raw Normal View History

2020-06-23 14:10:17 +02:00
import { catchError, switchMap, tap } from 'rxjs/operators'
2021-02-10 09:05:29 +01:00
import { SelectChannelItem } from 'src/types/select-options-item.model'
2020-08-06 16:14:58 +02:00
import { Directive, EventEmitter, OnInit } from '@angular/core'
2020-06-23 14:10:17 +02:00
import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
import { listUserChannelsForSelect } from '@app/helpers'
2021-02-10 09:05:29 +01:00
import { FormReactive } from '@app/shared/shared-forms'
2023-08-28 10:55:04 +02:00
import {
VideoCaptionEdit,
VideoCaptionService,
VideoChapterService,
VideoChaptersEdit,
VideoEdit,
VideoService
} from '@app/shared/shared-main'
2018-08-06 15:12:54 +02:00
import { LoadingBarService } from '@ngx-loading-bar/core'
import { HTMLServerConfig, VideoConstant, VideoPrivacyType } from '@peertube/peertube-models'
2023-08-28 10:55:04 +02:00
import { of } from 'rxjs'
2018-08-06 15:12:54 +02:00
2020-06-26 08:37:26 +02:00
@Directive()
2021-08-17 14:42:53 +02:00
// eslint-disable-next-line @angular-eslint/directive-class-suffix
2018-10-18 14:35:31 +02:00
export abstract class VideoSend extends FormReactive implements OnInit {
2020-08-11 09:22:42 +02:00
userVideoChannels: SelectChannelItem[] = []
videoPrivacies: VideoConstant<VideoPrivacyType>[] = []
2018-08-06 15:12:54 +02:00
videoCaptions: VideoCaptionEdit[] = []
2023-08-28 10:55:04 +02:00
chaptersEdit = new VideoChaptersEdit()
2018-08-06 15:12:54 +02:00
firstStepPrivacyId: VideoPrivacyType
firstStepChannelId: number
2018-08-06 15:12:54 +02:00
abstract firstStepDone: EventEmitter<string>
2018-11-16 10:05:25 +01:00
abstract firstStepError: EventEmitter<void>
2018-08-06 15:12:54 +02:00
protected loadingBar: LoadingBarService
protected notifier: Notifier
2018-08-06 15:12:54 +02:00
protected authService: AuthService
2018-08-06 15:12:54 +02:00
protected serverService: ServerService
protected videoService: VideoService
protected videoCaptionService: VideoCaptionService
2023-08-28 10:55:04 +02:00
protected videoChapterService: VideoChapterService
2021-06-04 13:31:41 +02:00
protected serverConfig: HTMLServerConfig
2018-08-06 15:12:54 +02:00
protected highestPrivacy: VideoPrivacyType
2018-10-18 14:35:31 +02:00
abstract canDeactivate (): CanComponentDeactivateResult
2018-08-06 15:12:54 +02:00
ngOnInit () {
this.buildForm({})
listUserChannelsForSelect(this.authService)
2021-02-25 09:09:41 +01:00
.subscribe(channels => {
this.userVideoChannels = channels
this.firstStepChannelId = this.userVideoChannels[0].id
})
2018-08-06 15:12:54 +02:00
2021-06-04 13:31:41 +02:00
this.serverConfig = this.serverService.getHTMLConfig()
2019-12-18 15:31:54 +01:00
this.serverService.getVideoPrivacies()
2018-08-06 15:12:54 +02:00
.subscribe(
2019-12-18 15:31:54 +01:00
privacies => {
const defaultPrivacy = this.serverConfig.defaults.publish.privacy
const { videoPrivacies, defaultPrivacyId } = this.videoService.explainedPrivacyLabels(privacies, defaultPrivacy)
2018-08-06 15:12:54 +02:00
this.videoPrivacies = videoPrivacies
this.firstStepPrivacyId = defaultPrivacyId
this.highestPrivacy = this.videoService.getHighestAvailablePrivacy(privacies)
2018-08-06 15:12:54 +02:00
})
}
2023-08-28 10:55:04 +02:00
protected updateVideoAndCaptionsAndChapters (options: {
video: VideoEdit
captions: VideoCaptionEdit[]
chapters?: VideoChaptersEdit
}) {
const { video, captions, chapters } = options
2020-08-06 16:14:58 +02:00
this.loadingBar.useRef().start()
2018-08-06 15:12:54 +02:00
return this.videoService.updateVideo(video)
.pipe(
2023-08-28 10:55:04 +02:00
switchMap(() => this.videoCaptionService.updateCaptions(video.uuid, captions)),
switchMap(() => {
return chapters
? this.videoChapterService.updateChapters(video.uuid, chapters)
: of(true)
}),
2020-08-06 16:14:58 +02:00
tap(() => this.loadingBar.useRef().complete()),
2018-08-06 15:12:54 +02:00
catchError(err => {
2020-08-06 16:14:58 +02:00
this.loadingBar.useRef().complete()
2018-08-06 15:12:54 +02:00
throw err
})
)
}
2021-12-29 15:33:24 +01:00
protected async isFormValid () {
await this.waitPendingCheck()
this.forceCheck()
return this.form.valid
}
2018-08-06 15:12:54 +02:00
}