]>
Commit | Line | Data |
---|---|---|
c199c427 | 1 | import { Component, ElementRef, EventEmitter, Input, 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' |
52d9f792 C |
6 | |
7 | @Component({ | |
8 | selector: 'my-actor-avatar-info', | |
9 | templateUrl: './actor-avatar-info.component.html', | |
10 | styleUrls: [ './actor-avatar-info.component.scss' ] | |
11 | }) | |
12 | export class ActorAvatarInfoComponent { | |
f36da21e | 13 | @ViewChild('avatarfileInput', { static: false }) avatarfileInput: ElementRef<HTMLInputElement> |
52d9f792 C |
14 | |
15 | @Input() actor: VideoChannel | Account | |
16 | ||
17 | @Output() avatarChange = new EventEmitter<FormData>() | |
18 | ||
19 | constructor ( | |
52d9f792 | 20 | private serverService: ServerService, |
f8b2c1b4 | 21 | private notifier: Notifier |
52d9f792 C |
22 | ) {} |
23 | ||
24 | onAvatarChange () { | |
25 | const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ] | |
26 | if (avatarfile.size > this.maxAvatarSize) { | |
f8b2c1b4 | 27 | this.notifier.error('Error', 'This image is too large.') |
52d9f792 C |
28 | return |
29 | } | |
30 | ||
31 | const formData = new FormData() | |
32 | formData.append('avatarfile', avatarfile) | |
33 | ||
34 | this.avatarChange.emit(formData) | |
35 | } | |
36 | ||
37 | get maxAvatarSize () { | |
38 | return this.serverService.getConfig().avatar.file.size.max | |
39 | } | |
40 | ||
41 | get avatarExtensions () { | |
42 | return this.serverService.getConfig().avatar.file.extensions.join(',') | |
43 | } | |
44 | } |