1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
import { Notifier, ServerService } from '@app/core'
import { getBytes } from '@root-helpers/bytes'
import { ServerConfig } from '@shared/models'
import { VideoChannel } from '../video-channel/video-channel.model'
import { Account } from '../account/account.model'
@Component({
selector: 'my-actor-avatar-info',
templateUrl: './actor-avatar-info.component.html',
styleUrls: [ './actor-avatar-info.component.scss' ]
})
export class ActorAvatarInfoComponent implements OnInit {
@ViewChild('avatarfileInput') avatarfileInput: ElementRef<HTMLInputElement>
@Input() actor: VideoChannel | Account
@Output() avatarChange = new EventEmitter<FormData>()
maxSizeText: string
private serverConfig: ServerConfig
constructor (
private serverService: ServerService,
private notifier: Notifier
) {
this.maxSizeText = $localize`max size`
}
ngOnInit (): void {
this.serverConfig = this.serverService.getTmpConfig()
this.serverService.getConfig()
.subscribe(config => this.serverConfig = config)
}
onAvatarChange () {
const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
if (avatarfile.size > this.maxAvatarSize) {
this.notifier.error('Error', 'This image is too large.')
return
}
const formData = new FormData()
formData.append('avatarfile', avatarfile)
this.avatarChange.emit(formData)
}
get maxAvatarSize () {
return this.serverConfig.avatar.file.size.max
}
get maxAvatarSizeInBytes () {
return getBytes(this.maxAvatarSize)
}
get avatarExtensions () {
return this.serverConfig.avatar.file.extensions.join(', ')
}
}
|