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