1 import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier, ServerService } from '@app/core'
3 import { Account, BytesPipe, VideoChannel } from '@app/shared/shared-main'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { ServerConfig } from '@shared/models'
8 selector: 'my-actor-avatar-info',
9 templateUrl: './actor-avatar-info.component.html',
10 styleUrls: [ './actor-avatar-info.component.scss' ]
12 export class ActorAvatarInfoComponent implements OnInit {
13 @ViewChild('avatarfileInput') avatarfileInput: ElementRef<HTMLInputElement>
15 @Input() actor: VideoChannel | Account
17 @Output() avatarChange = new EventEmitter<FormData>()
21 private serverConfig: ServerConfig
22 private bytesPipe: BytesPipe
25 private serverService: ServerService,
26 private notifier: Notifier,
29 this.bytesPipe = new BytesPipe()
30 this.maxSizeText = this.i18n('max size')
34 this.serverConfig = this.serverService.getTmpConfig()
35 this.serverService.getConfig()
36 .subscribe(config => this.serverConfig = config)
40 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
41 if (avatarfile.size > this.maxAvatarSize) {
42 this.notifier.error('Error', 'This image is too large.')
46 const formData = new FormData()
47 formData.append('avatarfile', avatarfile)
49 this.avatarChange.emit(formData)
52 get maxAvatarSize () {
53 return this.serverConfig.avatar.file.size.max
56 get maxAvatarSizeInBytes () {
57 return this.bytesPipe.transform(this.maxAvatarSize)
60 get avatarExtensions () {
61 return this.serverConfig.avatar.file.extensions.join(', ')