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