]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/images/preview-upload.component.ts
Support audio upload in client
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / images / preview-upload.component.ts
CommitLineData
7b992a86 1import { Component, forwardRef, Input, OnInit } from '@angular/core'
702785a5
C
2import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'
4import { ServerService } from '@app/core'
702785a5
C
5
6@Component({
7b992a86
C
7 selector: 'my-preview-upload',
8 styleUrls: [ './preview-upload.component.scss' ],
9 templateUrl: './preview-upload.component.html',
702785a5
C
10 providers: [
11 {
12 provide: NG_VALUE_ACCESSOR,
7b992a86 13 useExisting: forwardRef(() => PreviewUploadComponent),
702785a5
C
14 multi: true
15 }
16 ]
17})
7b992a86 18export class PreviewUploadComponent implements OnInit, ControlValueAccessor {
702785a5
C
19 @Input() inputLabel: string
20 @Input() inputName: string
21 @Input() previewWidth: string
22 @Input() previewHeight: string
23
24 imageSrc: SafeResourceUrl
7b992a86 25 allowedExtensionsMessage = ''
702785a5 26
40e87e9e 27 private file: File
702785a5
C
28
29 constructor (
30 private sanitizer: DomSanitizer,
40e87e9e 31 private serverService: ServerService
702785a5
C
32 ) {}
33
34 get videoImageExtensions () {
40e87e9e 35 return this.serverService.getConfig().video.image.extensions
702785a5
C
36 }
37
38 get maxVideoImageSize () {
39 return this.serverService.getConfig().video.image.size.max
40 }
41
7b992a86
C
42 ngOnInit () {
43 this.allowedExtensionsMessage = this.videoImageExtensions.join(', ')
44 }
45
40e87e9e
C
46 onFileChanged (file: File) {
47 this.file = file
0c237b19 48
40e87e9e
C
49 this.propagateChange(this.file)
50 this.updatePreview()
702785a5
C
51 }
52
53 propagateChange = (_: any) => { /* empty */ }
54
55 writeValue (file: any) {
56 this.file = file
57 this.updatePreview()
58 }
59
60 registerOnChange (fn: (_: any) => void) {
61 this.propagateChange = fn
62 }
63
64 registerOnTouched () {
65 // Unused
66 }
67
68 private updatePreview () {
69 if (this.file) {
70 const url = URL.createObjectURL(this.file)
71 this.imageSrc = this.sanitizer.bypassSecurityTrustResourceUrl(url)
72 }
73 }
74}