]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/account/actor-avatar-info.component.ts
Update ffmpeg min version
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / actor-avatar-info.component.ts
CommitLineData
e61151b0 1import { BytesPipe } from 'ngx-pipes'
67ed6552
C
2import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
3import { Notifier, ServerService } from '@app/core'
4import { Account, VideoChannel } from '@app/shared/shared-main'
e61151b0 5import { I18n } from '@ngx-translate/i18n-polyfill'
67ed6552 6import { ServerConfig } from '@shared/models'
52d9f792
C
7
8@Component({
9 selector: 'my-actor-avatar-info',
10 templateUrl: './actor-avatar-info.component.html',
11 styleUrls: [ './actor-avatar-info.component.scss' ]
12})
ba430d75 13export class ActorAvatarInfoComponent implements OnInit {
2f5d2ec5 14 @ViewChild('avatarfileInput') avatarfileInput: ElementRef<HTMLInputElement>
52d9f792
C
15
16 @Input() actor: VideoChannel | Account
17
18 @Output() avatarChange = new EventEmitter<FormData>()
19
e61151b0
RK
20 maxSizeText: string
21
ba430d75 22 private serverConfig: ServerConfig
e61151b0 23 private bytesPipe: BytesPipe
ba430d75 24
52d9f792 25 constructor (
52d9f792 26 private serverService: ServerService,
e61151b0
RK
27 private notifier: Notifier,
28 private i18n: I18n
29 ) {
30 this.bytesPipe = new BytesPipe()
31 this.maxSizeText = this.i18n('max size')
32 }
52d9f792 33
ba430d75
C
34 ngOnInit (): void {
35 this.serverConfig = this.serverService.getTmpConfig()
36 this.serverService.getConfig()
37 .subscribe(config => this.serverConfig = config)
38 }
39
52d9f792
C
40 onAvatarChange () {
41 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
42 if (avatarfile.size > this.maxAvatarSize) {
f8b2c1b4 43 this.notifier.error('Error', 'This image is too large.')
52d9f792
C
44 return
45 }
46
47 const formData = new FormData()
48 formData.append('avatarfile', avatarfile)
49
50 this.avatarChange.emit(formData)
51 }
52
53 get maxAvatarSize () {
ba430d75 54 return this.serverConfig.avatar.file.size.max
52d9f792
C
55 }
56
e61151b0
RK
57 get maxAvatarSizeInBytes () {
58 return this.bytesPipe.transform(this.maxAvatarSize)
59 }
60
52d9f792 61 get avatarExtensions () {
482fa503 62 return this.serverConfig.avatar.file.extensions.join(', ')
52d9f792
C
63 }
64}