]>
Commit | Line | Data |
---|---|---|
e61151b0 | 1 | import { BytesPipe } from 'ngx-pipes' |
67ed6552 C |
2 | import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
3 | import { Notifier, ServerService } from '@app/core' | |
4 | import { Account, VideoChannel } from '@app/shared/shared-main' | |
e61151b0 | 5 | import { I18n } from '@ngx-translate/i18n-polyfill' |
67ed6552 | 6 | import { ServerConfig } from '@shared/models' |
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 | ||
e61151b0 RK |
20 | maxSizeText: string |
21 | ||
ba430d75 | 22 | private serverConfig: ServerConfig |
e61151b0 | 23 | private bytesPipe: BytesPipe |
ba430d75 | 24 | |
52d9f792 | 25 | constructor ( |
52d9f792 | 26 | private serverService: ServerService, |
e61151b0 RK |
27 | private notifier: Notifier, |
28 | private i18n: I18n | |
29 | ) { | |
30 | this.bytesPipe = new BytesPipe() | |
31 | this.maxSizeText = this.i18n('max size') | |
32 | } | |
52d9f792 | 33 | |
ba430d75 C |
34 | ngOnInit (): void { |
35 | this.serverConfig = this.serverService.getTmpConfig() | |
36 | this.serverService.getConfig() | |
37 | .subscribe(config => this.serverConfig = config) | |
38 | } | |
39 | ||
52d9f792 C |
40 | onAvatarChange () { |
41 | const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ] | |
42 | if (avatarfile.size > this.maxAvatarSize) { | |
f8b2c1b4 | 43 | this.notifier.error('Error', 'This image is too large.') |
52d9f792 C |
44 | return |
45 | } | |
46 | ||
47 | const formData = new FormData() | |
48 | formData.append('avatarfile', avatarfile) | |
49 | ||
50 | this.avatarChange.emit(formData) | |
51 | } | |
52 | ||
53 | get maxAvatarSize () { | |
ba430d75 | 54 | return this.serverConfig.avatar.file.size.max |
52d9f792 C |
55 | } |
56 | ||
e61151b0 RK |
57 | get maxAvatarSizeInBytes () { |
58 | return this.bytesPipe.transform(this.maxAvatarSize) | |
59 | } | |
60 | ||
52d9f792 | 61 | get avatarExtensions () { |
482fa503 | 62 | return this.serverConfig.avatar.file.extensions.join(', ') |
52d9f792 C |
63 | } |
64 | } |