1 import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier, ServerService } from '@app/core'
3 import { getBytes } from '@root-helpers/bytes'
4 import { ServerConfig } from '@shared/models'
5 import { VideoChannel } from '../video-channel/video-channel.model'
6 import { Account } from '../account/account.model'
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>()
20 private serverConfig: ServerConfig
23 private serverService: ServerService,
24 private notifier: Notifier
28 this.serverConfig = this.serverService.getTmpConfig()
29 this.serverService.getConfig()
30 .subscribe(config => this.serverConfig = config)
34 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
35 if (avatarfile.size > this.maxAvatarSize) {
36 this.notifier.error('Error', 'This image is too large.')
40 const formData = new FormData()
41 formData.append('avatarfile', avatarfile)
43 this.avatarChange.emit(formData)
46 get maxAvatarSize () {
47 return this.serverConfig.avatar.file.size.max
50 get maxAvatarSizeInBytes () {
51 return getBytes(this.maxAvatarSize)
54 get avatarExtensions () {
55 return this.serverConfig.avatar.file.extensions.join(', ')
59 return `${$localize`max size`}: 192*192px, ${this.maxAvatarSizeInBytes} ${$localize`extensions`}: ${this.avatarExtensions}`