1 import { BytesPipe } from 'ngx-pipes'
2 import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
3 import { Notifier, ServerService } from '@app/core'
4 import { Account, VideoChannel } from '@app/shared/shared-main'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { ServerConfig } from '@shared/models'
9 selector: 'my-actor-avatar-info',
10 templateUrl: './actor-avatar-info.component.html',
11 styleUrls: [ './actor-avatar-info.component.scss' ]
13 export class ActorAvatarInfoComponent implements OnInit {
14 @ViewChild('avatarfileInput') avatarfileInput: ElementRef<HTMLInputElement>
16 @Input() actor: VideoChannel | Account
18 @Output() avatarChange = new EventEmitter<FormData>()
22 private serverConfig: ServerConfig
23 private bytesPipe: BytesPipe
26 private serverService: ServerService,
27 private notifier: Notifier,
30 this.bytesPipe = new BytesPipe()
31 this.maxSizeText = this.i18n('max size')
35 this.serverConfig = this.serverService.getTmpConfig()
36 this.serverService.getConfig()
37 .subscribe(config => this.serverConfig = config)
41 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
42 if (avatarfile.size > this.maxAvatarSize) {
43 this.notifier.error('Error', 'This image is too large.')
47 const formData = new FormData()
48 formData.append('avatarfile', avatarfile)
50 this.avatarChange.emit(formData)
53 get maxAvatarSize () {
54 return this.serverConfig.avatar.file.size.max
57 get maxAvatarSizeInBytes () {
58 return this.bytesPipe.transform(this.maxAvatarSize)
61 get avatarExtensions () {
62 return this.serverConfig.avatar.file.extensions.join(', ')