]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts
Cleanup video playlist element miniature code
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add-components / video-upload.component.ts
index 189bc966977b20671385fc4524d18e42d4cfc211..6f72a07c4a856c50b730e3cf4b55614fdd3d3c49 100644 (file)
@@ -7,9 +7,10 @@ import { genericUploadErrorHandler, scrollToTop } from '@app/helpers'
 import { FormValidatorService } from '@app/shared/shared-forms'
 import { BytesPipe, Video, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
 import { LoadingBarService } from '@ngx-loading-bar/core'
-import { HttpStatusCode, VideoPrivacy } from '@shared/models'
+import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
 import { UploaderXFormData } from './uploaderx-form-data'
 import { VideoSend } from './video-send'
+import { isIOS } from 'src/assets/player/utils'
 
 @Component({
   selector: 'my-video-upload',
@@ -33,9 +34,10 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
 
   videoUploaded = false
   videoUploadPercents = 0
-  videoUploadedIds = {
+  videoUploadedIds: VideoCreateResult = {
     id: 0,
-    uuid: ''
+    uuid: '',
+    shortUUID: ''
   }
   formData: FormData
 
@@ -68,11 +70,17 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
   ) {
     super()
 
+    // FIXME: https://github.com/Chocobozzz/PeerTube/issues/4382#issuecomment-915854167
+    const chunkSize = isIOS()
+      ? 0
+      : undefined // Auto chunk size
+
     this.uploadxOptions = {
       endpoint: this.BASE_VIDEO_UPLOAD_URL,
       multiple: false,
       token: this.authService.getAccessToken(),
       uploaderClass: UploaderXFormData,
+      chunkSize,
       retryConfig: {
         maxAttempts: 6,
         shouldRetry: (code: number) => {
@@ -113,7 +121,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
     let text = ''
 
     if (this.videoUploaded === true) {
-      // FIXME: cannot concatenate strings using $localize
+      // We can't concatenate strings using $localize
       text = $localize`Your video was uploaded to your account and is private.` + ' ' +
         $localize`But associated data (tags, description...) will be lost, are you sure you want to leave this page?`
     } else {
@@ -128,7 +136,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
 
   onUploadVideoOngoing (state: UploadState) {
     switch (state.status) {
-      case 'error':
+      case 'error': {
         const error = state.response?.error || 'Unknow error'
 
         this.handleUploadError({
@@ -143,6 +151,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
           url: state.url
         })
         break
+      }
 
       case 'cancelled':
         this.isUploadingVideo = false
@@ -236,12 +245,13 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
     video.patch(this.form.value)
     video.id = this.videoUploadedIds.id
     video.uuid = this.videoUploadedIds.uuid
+    video.shortUUID = this.videoUploadedIds.shortUUID
 
     this.isUpdatingVideo = true
 
     this.updateVideoAndCaptions(video)
-        .subscribe(
-          () => {
+        .subscribe({
+          next: () => {
             this.isUpdatingVideo = false
             this.isUploadingVideo = false
 
@@ -249,12 +259,12 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
             this.router.navigateByUrl(Video.buildWatchUrl(video))
           },
 
-          err => {
+          error: err => {
             this.error = err.message
             scrollToTop()
             console.error(err)
           }
-        )
+        })
   }
 
   private getInputVideoFile () {
@@ -323,6 +333,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
       const videoQuotaUsedBytes = bytePipes.transform(this.userVideoQuotaUsed, 0)
       const videoQuotaBytes = bytePipes.transform(videoQuota, 0)
 
+      // eslint-disable-next-line max-len
       const msg = $localize`Your video quota is exceeded with this video (video size: ${videoSizeBytes}, used: ${videoQuotaUsedBytes}, quota: ${videoQuotaBytes})`
       this.notifier.error(msg)
 
@@ -341,6 +352,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
       const videoSizeBytes = bytePipes.transform(videofile.size, 0)
       const quotaUsedDailyBytes = bytePipes.transform(this.userVideoQuotaUsedDaily, 0)
       const quotaDailyBytes = bytePipes.transform(videoQuotaDaily, 0)
+      // eslint-disable-next-line max-len
       const msg = $localize`Your daily video quota is exceeded with this video (video size: ${videoSizeBytes}, used: ${quotaUsedDailyBytes}, quota: ${quotaDailyBytes})`
       this.notifier.error(msg)