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>()
22 private serverConfig: ServerConfig
25 private serverService: ServerService,
26 private notifier: Notifier
28 this.maxSizeText = $localize`max size`
32 this.serverConfig = this.serverService.getTmpConfig()
33 this.serverService.getConfig()
34 .subscribe(config => this.serverConfig = config)
38 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
39 if (avatarfile.size > this.maxAvatarSize) {
40 this.notifier.error('Error', 'This image is too large.')
44 const formData = new FormData()
45 formData.append('avatarfile', avatarfile)
47 this.avatarChange.emit(formData)
50 get maxAvatarSize () {
51 return this.serverConfig.avatar.file.size.max
54 get maxAvatarSizeInBytes () {
55 return getBytes(this.maxAvatarSize)
58 get avatarExtensions () {
59 return this.serverConfig.avatar.file.extensions.join(', ')