+import { switchMap } from 'rxjs'
import { AfterViewInit, Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
import { Router } from '@angular/router'
import { AuthService, CanComponentDeactivate, HooksService, Notifier, ServerService } from '@app/core'
this.loadingBar.useRef().start()
this.videoImportService.importVideoTorrent(torrentfile || this.magnetUri, videoUpdate)
+ .pipe(switchMap(({ video }) => this.videoService.getVideo({ videoId: video.uuid })))
.subscribe({
- next: res => {
+ next: video => {
this.loadingBar.useRef().complete()
- this.firstStepDone.emit(res.video.name)
+ this.firstStepDone.emit(video.name)
this.isImportingVideo = false
this.hasImportedVideo = true
- this.video = new VideoEdit(Object.assign(res.video, {
- commentsEnabled: videoUpdate.commentsEnabled,
- downloadEnabled: videoUpdate.downloadEnabled,
- privacy: { id: this.firstStepPrivacyId },
- support: null,
- thumbnailUrl: null,
- previewUrl: null
- }))
+ this.video = new VideoEdit(video)
+ this.video.patch({ privacy: this.firstStepPrivacyId })
hydrateFormFromVideo(this.form, this.video, false)
},
+import { forkJoin } from 'rxjs'
import { map, switchMap } from 'rxjs/operators'
import { AfterViewInit, Component, EventEmitter, OnInit, Output } from '@angular/core'
import { Router } from '@angular/router'
import { AuthService, CanComponentDeactivate, HooksService, Notifier, ServerService } from '@app/core'
-import { getAbsoluteAPIUrl, scrollToTop } from '@app/helpers'
+import { scrollToTop } from '@app/helpers'
import { FormValidatorService } from '@app/shared/shared-forms'
import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main'
import { LoadingBarService } from '@ngx-loading-bar/core'
this.videoImportService
.importVideoUrl(this.targetUrl, videoUpdate)
.pipe(
- switchMap(res => {
- return this.videoCaptionService
- .listCaptions(res.video.uuid)
- .pipe(
- map(result => ({ video: res.video, videoCaptions: result.data }))
- )
+ switchMap(previous => {
+ return forkJoin([
+ this.videoCaptionService.listCaptions(previous.video.uuid),
+ this.videoService.getVideo({ videoId: previous.video.uuid })
+ ]).pipe(map(([ videoCaptionsResult, video ]) => ({ videoCaptions: videoCaptionsResult.data, video })))
})
)
.subscribe({
this.isImportingVideo = false
this.hasImportedVideo = true
- const absoluteAPIUrl = getAbsoluteAPIUrl()
-
- const thumbnailUrl = video.thumbnailPath
- ? absoluteAPIUrl + video.thumbnailPath
- : null
-
- const previewUrl = video.previewPath
- ? absoluteAPIUrl + video.previewPath
- : null
-
- this.video = new VideoEdit(Object.assign(video, {
- commentsEnabled: videoUpdate.commentsEnabled,
- downloadEnabled: videoUpdate.downloadEnabled,
- privacy: { id: this.firstStepPrivacyId },
- support: null,
- thumbnailUrl,
- previewUrl
- }))
+ this.video = new VideoEdit(video)
+ this.video.patch({ privacy: this.firstStepPrivacyId })
this.videoCaptions = videoCaptions
<div class="margin-content">
<div class="title-page">
<span class="me-1" i18n>Update</span>
- <a [routerLink]="getVideoUrl()">{{ video?.name }}</a>
+ <a [routerLink]="getVideoUrl()">{{ videoDetails?.name }}</a>
</div>
<form novalidate [formGroup]="form">
templateUrl: './video-update.component.html'
})
export class VideoUpdateComponent extends FormReactive implements OnInit {
- video: VideoEdit
+ videoEdit: VideoEdit
videoDetails: VideoDetails
videoSource: VideoSource
userVideoChannels: SelectChannelItem[] = []
const { videoData } = this.route.snapshot.data
const { video, videoChannels, videoCaptions, videoSource, liveVideo } = videoData
- this.video = new VideoEdit(video)
this.videoDetails = video
+ this.videoEdit = new VideoEdit(this.videoDetails)
this.userVideoChannels = videoChannels
this.videoCaptions = videoCaptions
this.videoSource = videoSource
this.liveVideo = liveVideo
- this.forbidScheduledPublication = this.video.privacy !== VideoPrivacy.PRIVATE
+ this.forbidScheduledPublication = this.videoEdit.privacy !== VideoPrivacy.PRIVATE
}
onFormBuilt () {
- hydrateFormFromVideo(this.form, this.video, true)
+ hydrateFormFromVideo(this.form, this.videoEdit, true)
if (this.liveVideo) {
this.form.patchValue({
return
}
- this.video.patch(this.form.value)
+ this.videoEdit.patch(this.form.value)
this.loadingBar.useRef().start()
this.isUpdatingVideo = true
// Update the video
- this.videoService.updateVideo(this.video)
+ this.videoService.updateVideo(this.videoEdit)
.pipe(
// Then update captions
- switchMap(() => this.videoCaptionService.updateCaptions(this.video.id, this.videoCaptions)),
+ switchMap(() => this.videoCaptionService.updateCaptions(this.videoEdit.id, this.videoCaptions)),
switchMap(() => {
if (!this.liveVideo) return of(undefined)
.some(key => this.liveVideo[key] !== liveVideoUpdate[key])
if (!liveChanged) return of(undefined)
- return this.liveVideoService.updateLive(this.video.id, liveVideoUpdate)
+ return this.liveVideoService.updateLive(this.videoEdit.id, liveVideoUpdate)
})
)
.subscribe({
this.isUpdatingVideo = false
this.loadingBar.useRef().complete()
this.notifier.success($localize`Video updated.`)
- this.router.navigateByUrl(Video.buildWatchUrl(this.video))
+ this.router.navigateByUrl(Video.buildWatchUrl(this.videoEdit))
},
error: err => {
}
hydratePluginFieldsFromVideo () {
- if (!this.video.pluginData) return
+ if (!this.videoEdit.pluginData) return
this.form.patchValue({
- pluginData: this.video.pluginData
+ pluginData: this.videoEdit.pluginData
})
}
-import { Video, VideoPrivacy, VideoScheduleUpdate, VideoUpdate } from '@shared/models'
+import { getAbsoluteAPIUrl } from '@app/helpers'
+import { VideoPrivacy, VideoScheduleUpdate, VideoUpdate } from '@shared/models'
+import { VideoDetails } from './video-details.model'
export class VideoEdit implements VideoUpdate {
static readonly SPECIAL_SCHEDULED_PRIVACY = -1
pluginData?: any
- constructor (
- video?: Video & {
- tags: string[]
- commentsEnabled: boolean
- downloadEnabled: boolean
- support: string
- thumbnailUrl: string
- previewUrl: string
- }) {
- if (video) {
- this.id = video.id
- this.uuid = video.uuid
- this.shortUUID = video.shortUUID
- this.category = video.category.id
- this.licence = video.licence.id
- this.language = video.language.id
- this.description = video.description
- this.name = video.name
- this.tags = video.tags
- this.nsfw = video.nsfw
- this.commentsEnabled = video.commentsEnabled
- this.downloadEnabled = video.downloadEnabled
- this.waitTranscoding = video.waitTranscoding
- this.channelId = video.channel.id
- this.privacy = video.privacy.id
- this.support = video.support
- this.thumbnailUrl = video.thumbnailUrl
- this.previewUrl = video.previewUrl
-
- this.scheduleUpdate = video.scheduledUpdate
- this.originallyPublishedAt = video.originallyPublishedAt ? new Date(video.originallyPublishedAt) : null
-
- this.pluginData = video.pluginData
- }
+ constructor (video?: VideoDetails) {
+ if (!video) return
+
+ this.id = video.id
+ this.uuid = video.uuid
+ this.shortUUID = video.shortUUID
+ this.category = video.category.id
+ this.licence = video.licence.id
+ this.language = video.language.id
+ this.description = video.description
+ this.name = video.name
+ this.tags = video.tags
+ this.nsfw = video.nsfw
+ this.waitTranscoding = video.waitTranscoding
+ this.channelId = video.channel.id
+ this.privacy = video.privacy.id
+ this.commentsEnabled = video.commentsEnabled
+ this.downloadEnabled = video.downloadEnabled
+
+ if (video.thumbnailPath) this.thumbnailUrl = getAbsoluteAPIUrl() + video.thumbnailPath
+ if (video.previewPath) this.previewUrl = getAbsoluteAPIUrl() + video.previewPath
+
+ this.scheduleUpdate = video.scheduledUpdate
+ this.originallyPublishedAt = video.originallyPublishedAt
+ ? new Date(video.originallyPublishedAt)
+ : null
+
+ this.pluginData = video.pluginData
}
patch (values: { [ id: string ]: any }) {
// Convert originallyPublishedAt to string so that function objectToFormData() works correctly
if (this.originallyPublishedAt) {
- const originallyPublishedAt = new Date(values['originallyPublishedAt'])
+ const originallyPublishedAt = new Date(this.originallyPublishedAt)
this.originallyPublishedAt = originallyPublishedAt.toISOString()
}