mirror of https://github.com/Chocobozzz/PeerTube
Fix comments/download attributes on import
parent
cd25344f74
commit
0146f3516e
|
@ -1,3 +1,4 @@
|
|||
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'
|
||||
|
@ -87,21 +88,16 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Af
|
|||
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)
|
||||
},
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
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'
|
||||
|
@ -76,12 +77,11 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, AfterV
|
|||
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({
|
||||
|
@ -91,24 +91,8 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, AfterV
|
|||
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
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<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">
|
||||
|
|
|
@ -18,7 +18,7 @@ import { VideoSource } from '@shared/models/videos/video-source'
|
|||
templateUrl: './video-update.component.html'
|
||||
})
|
||||
export class VideoUpdateComponent extends FormReactive implements OnInit {
|
||||
video: VideoEdit
|
||||
videoEdit: VideoEdit
|
||||
videoDetails: VideoDetails
|
||||
videoSource: VideoSource
|
||||
userVideoChannels: SelectChannelItem[] = []
|
||||
|
@ -50,19 +50,19 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
|||
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({
|
||||
|
@ -115,16 +115,16 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
|||
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)
|
||||
|
@ -140,7 +140,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
|||
.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({
|
||||
|
@ -149,7 +149,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
|||
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 => {
|
||||
|
@ -162,10 +162,10 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
|||
}
|
||||
|
||||
hydratePluginFieldsFromVideo () {
|
||||
if (!this.video.pluginData) return
|
||||
if (!this.videoEdit.pluginData) return
|
||||
|
||||
this.form.patchValue({
|
||||
pluginData: this.video.pluginData
|
||||
pluginData: this.videoEdit.pluginData
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
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
|
||||
|
@ -29,40 +31,34 @@ export class VideoEdit implements VideoUpdate {
|
|||
|
||||
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
|
||||
constructor (video?: VideoDetails) {
|
||||
if (!video) return
|
||||
|
||||
this.scheduleUpdate = video.scheduledUpdate
|
||||
this.originallyPublishedAt = video.originallyPublishedAt ? new Date(video.originallyPublishedAt) : null
|
||||
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
|
||||
|
||||
this.pluginData = video.pluginData
|
||||
}
|
||||
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 }) {
|
||||
|
@ -86,7 +82,7 @@ export class VideoEdit implements VideoUpdate {
|
|||
|
||||
// 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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue