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