]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix comments/download attributes on import
authorChocobozzz <me@florianbigard.com>
Mon, 4 Jul 2022 09:31:22 +0000 (11:31 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 4 Jul 2022 09:31:22 +0000 (11:31 +0200)
client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts
client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.ts
client/src/app/+videos/+video-edit/video-update.component.html
client/src/app/+videos/+video-edit/video-update.component.ts
client/src/app/shared/shared-main/video/video-edit.model.ts

index c369ba2b7a156efc81ab8602477dc9b89585834e..da49969025d671270ed622af2a7fc0f29885238d 100644 (file)
@@ -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)
         },
index 4c74eda845fffc60dccc658b0001044b0f6c1765..971a2a070edac6f3386aa91e79ffc16ad0a037bd 100644 (file)
@@ -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
 
index ffd125695b00d4aecb007dcec32d446e2d0c66f6..a33ac3db4c53f514760697cb4bbdb4f7f182a861 100644 (file)
@@ -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">
index 43e8ba3e566c41b38b4cb5ed674d95ae400746ad..13e786a8eed988b04cb9c7db2e41ccecf93130a6 100644 (file)
@@ -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
     })
   }
 
index 3922ee42a9540f9f23ce23bc42bc278e6dd1587e..4cff01653f6f6a17be217ccf18f5f76046372a38 100644 (file)
@@ -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
-
-      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 }) {
@@ -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()
     }