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 { AfterViewInit, Component, ElementRef, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
|
||||||
import { Router } from '@angular/router'
|
import { Router } from '@angular/router'
|
||||||
import { AuthService, CanComponentDeactivate, HooksService, Notifier, ServerService } from '@app/core'
|
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.loadingBar.useRef().start()
|
||||||
|
|
||||||
this.videoImportService.importVideoTorrent(torrentfile || this.magnetUri, videoUpdate)
|
this.videoImportService.importVideoTorrent(torrentfile || this.magnetUri, videoUpdate)
|
||||||
|
.pipe(switchMap(({ video }) => this.videoService.getVideo({ videoId: video.uuid })))
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: res => {
|
next: video => {
|
||||||
this.loadingBar.useRef().complete()
|
this.loadingBar.useRef().complete()
|
||||||
this.firstStepDone.emit(res.video.name)
|
this.firstStepDone.emit(video.name)
|
||||||
this.isImportingVideo = false
|
this.isImportingVideo = false
|
||||||
this.hasImportedVideo = true
|
this.hasImportedVideo = true
|
||||||
|
|
||||||
this.video = new VideoEdit(Object.assign(res.video, {
|
this.video = new VideoEdit(video)
|
||||||
commentsEnabled: videoUpdate.commentsEnabled,
|
this.video.patch({ privacy: this.firstStepPrivacyId })
|
||||||
downloadEnabled: videoUpdate.downloadEnabled,
|
|
||||||
privacy: { id: this.firstStepPrivacyId },
|
|
||||||
support: null,
|
|
||||||
thumbnailUrl: null,
|
|
||||||
previewUrl: null
|
|
||||||
}))
|
|
||||||
|
|
||||||
hydrateFormFromVideo(this.form, this.video, false)
|
hydrateFormFromVideo(this.form, this.video, false)
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
import { forkJoin } from 'rxjs'
|
||||||
import { map, switchMap } from 'rxjs/operators'
|
import { map, switchMap } from 'rxjs/operators'
|
||||||
import { AfterViewInit, Component, EventEmitter, OnInit, Output } from '@angular/core'
|
import { AfterViewInit, Component, EventEmitter, OnInit, Output } from '@angular/core'
|
||||||
import { Router } from '@angular/router'
|
import { Router } from '@angular/router'
|
||||||
import { AuthService, CanComponentDeactivate, HooksService, Notifier, ServerService } from '@app/core'
|
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 { FormValidatorService } from '@app/shared/shared-forms'
|
||||||
import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main'
|
import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main'
|
||||||
import { LoadingBarService } from '@ngx-loading-bar/core'
|
import { LoadingBarService } from '@ngx-loading-bar/core'
|
||||||
|
@ -76,12 +77,11 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, AfterV
|
||||||
this.videoImportService
|
this.videoImportService
|
||||||
.importVideoUrl(this.targetUrl, videoUpdate)
|
.importVideoUrl(this.targetUrl, videoUpdate)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(res => {
|
switchMap(previous => {
|
||||||
return this.videoCaptionService
|
return forkJoin([
|
||||||
.listCaptions(res.video.uuid)
|
this.videoCaptionService.listCaptions(previous.video.uuid),
|
||||||
.pipe(
|
this.videoService.getVideo({ videoId: previous.video.uuid })
|
||||||
map(result => ({ video: res.video, videoCaptions: result.data }))
|
]).pipe(map(([ videoCaptionsResult, video ]) => ({ videoCaptions: videoCaptionsResult.data, video })))
|
||||||
)
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
|
@ -91,24 +91,8 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, AfterV
|
||||||
this.isImportingVideo = false
|
this.isImportingVideo = false
|
||||||
this.hasImportedVideo = true
|
this.hasImportedVideo = true
|
||||||
|
|
||||||
const absoluteAPIUrl = getAbsoluteAPIUrl()
|
this.video = new VideoEdit(video)
|
||||||
|
this.video.patch({ privacy: this.firstStepPrivacyId })
|
||||||
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.videoCaptions = videoCaptions
|
this.videoCaptions = videoCaptions
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="margin-content">
|
<div class="margin-content">
|
||||||
<div class="title-page">
|
<div class="title-page">
|
||||||
<span class="me-1" i18n>Update</span>
|
<span class="me-1" i18n>Update</span>
|
||||||
<a [routerLink]="getVideoUrl()">{{ video?.name }}</a>
|
<a [routerLink]="getVideoUrl()">{{ videoDetails?.name }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form novalidate [formGroup]="form">
|
<form novalidate [formGroup]="form">
|
||||||
|
|
|
@ -18,7 +18,7 @@ import { VideoSource } from '@shared/models/videos/video-source'
|
||||||
templateUrl: './video-update.component.html'
|
templateUrl: './video-update.component.html'
|
||||||
})
|
})
|
||||||
export class VideoUpdateComponent extends FormReactive implements OnInit {
|
export class VideoUpdateComponent extends FormReactive implements OnInit {
|
||||||
video: VideoEdit
|
videoEdit: VideoEdit
|
||||||
videoDetails: VideoDetails
|
videoDetails: VideoDetails
|
||||||
videoSource: VideoSource
|
videoSource: VideoSource
|
||||||
userVideoChannels: SelectChannelItem[] = []
|
userVideoChannels: SelectChannelItem[] = []
|
||||||
|
@ -50,19 +50,19 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
||||||
const { videoData } = this.route.snapshot.data
|
const { videoData } = this.route.snapshot.data
|
||||||
const { video, videoChannels, videoCaptions, videoSource, liveVideo } = videoData
|
const { video, videoChannels, videoCaptions, videoSource, liveVideo } = videoData
|
||||||
|
|
||||||
this.video = new VideoEdit(video)
|
|
||||||
this.videoDetails = video
|
this.videoDetails = video
|
||||||
|
this.videoEdit = new VideoEdit(this.videoDetails)
|
||||||
|
|
||||||
this.userVideoChannels = videoChannels
|
this.userVideoChannels = videoChannels
|
||||||
this.videoCaptions = videoCaptions
|
this.videoCaptions = videoCaptions
|
||||||
this.videoSource = videoSource
|
this.videoSource = videoSource
|
||||||
this.liveVideo = liveVideo
|
this.liveVideo = liveVideo
|
||||||
|
|
||||||
this.forbidScheduledPublication = this.video.privacy !== VideoPrivacy.PRIVATE
|
this.forbidScheduledPublication = this.videoEdit.privacy !== VideoPrivacy.PRIVATE
|
||||||
}
|
}
|
||||||
|
|
||||||
onFormBuilt () {
|
onFormBuilt () {
|
||||||
hydrateFormFromVideo(this.form, this.video, true)
|
hydrateFormFromVideo(this.form, this.videoEdit, true)
|
||||||
|
|
||||||
if (this.liveVideo) {
|
if (this.liveVideo) {
|
||||||
this.form.patchValue({
|
this.form.patchValue({
|
||||||
|
@ -115,16 +115,16 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.video.patch(this.form.value)
|
this.videoEdit.patch(this.form.value)
|
||||||
|
|
||||||
this.loadingBar.useRef().start()
|
this.loadingBar.useRef().start()
|
||||||
this.isUpdatingVideo = true
|
this.isUpdatingVideo = true
|
||||||
|
|
||||||
// Update the video
|
// Update the video
|
||||||
this.videoService.updateVideo(this.video)
|
this.videoService.updateVideo(this.videoEdit)
|
||||||
.pipe(
|
.pipe(
|
||||||
// Then update captions
|
// Then update captions
|
||||||
switchMap(() => this.videoCaptionService.updateCaptions(this.video.id, this.videoCaptions)),
|
switchMap(() => this.videoCaptionService.updateCaptions(this.videoEdit.id, this.videoCaptions)),
|
||||||
|
|
||||||
switchMap(() => {
|
switchMap(() => {
|
||||||
if (!this.liveVideo) return of(undefined)
|
if (!this.liveVideo) return of(undefined)
|
||||||
|
@ -140,7 +140,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
||||||
.some(key => this.liveVideo[key] !== liveVideoUpdate[key])
|
.some(key => this.liveVideo[key] !== liveVideoUpdate[key])
|
||||||
if (!liveChanged) return of(undefined)
|
if (!liveChanged) return of(undefined)
|
||||||
|
|
||||||
return this.liveVideoService.updateLive(this.video.id, liveVideoUpdate)
|
return this.liveVideoService.updateLive(this.videoEdit.id, liveVideoUpdate)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
|
@ -149,7 +149,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
||||||
this.isUpdatingVideo = false
|
this.isUpdatingVideo = false
|
||||||
this.loadingBar.useRef().complete()
|
this.loadingBar.useRef().complete()
|
||||||
this.notifier.success($localize`Video updated.`)
|
this.notifier.success($localize`Video updated.`)
|
||||||
this.router.navigateByUrl(Video.buildWatchUrl(this.video))
|
this.router.navigateByUrl(Video.buildWatchUrl(this.videoEdit))
|
||||||
},
|
},
|
||||||
|
|
||||||
error: err => {
|
error: err => {
|
||||||
|
@ -162,10 +162,10 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
hydratePluginFieldsFromVideo () {
|
hydratePluginFieldsFromVideo () {
|
||||||
if (!this.video.pluginData) return
|
if (!this.videoEdit.pluginData) return
|
||||||
|
|
||||||
this.form.patchValue({
|
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 {
|
export class VideoEdit implements VideoUpdate {
|
||||||
static readonly SPECIAL_SCHEDULED_PRIVACY = -1
|
static readonly SPECIAL_SCHEDULED_PRIVACY = -1
|
||||||
|
@ -29,40 +31,34 @@ export class VideoEdit implements VideoUpdate {
|
||||||
|
|
||||||
pluginData?: any
|
pluginData?: any
|
||||||
|
|
||||||
constructor (
|
constructor (video?: VideoDetails) {
|
||||||
video?: Video & {
|
if (!video) return
|
||||||
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.id = video.id
|
||||||
this.originallyPublishedAt = video.originallyPublishedAt ? new Date(video.originallyPublishedAt) : null
|
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 }) {
|
patch (values: { [ id: string ]: any }) {
|
||||||
|
@ -86,7 +82,7 @@ export class VideoEdit implements VideoUpdate {
|
||||||
|
|
||||||
// Convert originallyPublishedAt to string so that function objectToFormData() works correctly
|
// Convert originallyPublishedAt to string so that function objectToFormData() works correctly
|
||||||
if (this.originallyPublishedAt) {
|
if (this.originallyPublishedAt) {
|
||||||
const originallyPublishedAt = new Date(values['originallyPublishedAt'])
|
const originallyPublishedAt = new Date(this.originallyPublishedAt)
|
||||||
this.originallyPublishedAt = originallyPublishedAt.toISOString()
|
this.originallyPublishedAt = originallyPublishedAt.toISOString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue