]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-forms/preview-upload.component.ts
Add transcoding fail message in client
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-forms / preview-upload.component.ts
index 7519734ba291eb7dca82fa0caaa42aae670fbbdd..a857b0a4f975648dbf798905494dc8c32e837890 100644 (file)
@@ -1,10 +1,9 @@
 import { Component, forwardRef, Input, OnInit } from '@angular/core'
 import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
-import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'
 import { ServerService } from '@app/core'
-import { ServerConfig } from '@shared/models'
-import { BytesPipe } from 'ngx-pipes'
-import { I18n } from '@ngx-translate/i18n-polyfill'
+import { imageToDataURL } from '@root-helpers/images'
+import { HTMLServerConfig } from '@shared/models'
+import { BytesPipe } from '../shared-main'
 
 @Component({
   selector: 'my-preview-upload',
@@ -24,21 +23,19 @@ export class PreviewUploadComponent implements OnInit, ControlValueAccessor {
   @Input() previewWidth: string
   @Input() previewHeight: string
 
-  imageSrc: SafeResourceUrl
+  imageSrc: string
   allowedExtensionsMessage = ''
   maxSizeText: string
 
-  private serverConfig: ServerConfig
+  private serverConfig: HTMLServerConfig
   private bytesPipe: BytesPipe
   private file: Blob
 
   constructor (
-    private sanitizer: DomSanitizer,
-    private serverService: ServerService,
-    private i18n: I18n
+    private serverService: ServerService
   ) {
     this.bytesPipe = new BytesPipe()
-    this.maxSizeText = this.i18n('max size')
+    this.maxSizeText = $localize`max size`
   }
 
   get videoImageExtensions () {
@@ -54,9 +51,7 @@ export class PreviewUploadComponent implements OnInit, ControlValueAccessor {
   }
 
   ngOnInit () {
-    this.serverConfig = this.serverService.getTmpConfig()
-    this.serverService.getConfig()
-      .subscribe(config => this.serverConfig = config)
+    this.serverConfig = this.serverService.getHTMLConfig()
 
     this.allowedExtensionsMessage = this.videoImageExtensions.join(', ')
   }
@@ -85,8 +80,7 @@ export class PreviewUploadComponent implements OnInit, ControlValueAccessor {
 
   private updatePreview () {
     if (this.file) {
-      const url = URL.createObjectURL(this.file)
-      this.imageSrc = this.sanitizer.bypassSecurityTrustResourceUrl(url)
+      imageToDataURL(this.file).then(result => this.imageSrc = result)
     }
   }
 }