aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/shared-main/account/actor-avatar-info.component.ts')
-rw-r--r--client/src/app/shared/shared-main/account/actor-avatar-info.component.ts64
1 files changed, 64 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts b/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts
new file mode 100644
index 000000000..0c04ae4a6
--- /dev/null
+++ b/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts
@@ -0,0 +1,64 @@
1import { BytesPipe } from 'ngx-pipes'
2import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
3import { Notifier, ServerService } from '@app/core'
4import { Account, VideoChannel } from '@app/shared/shared-main'
5import { I18n } from '@ngx-translate/i18n-polyfill'
6import { ServerConfig } from '@shared/models'
7
8@Component({
9 selector: 'my-actor-avatar-info',
10 templateUrl: './actor-avatar-info.component.html',
11 styleUrls: [ './actor-avatar-info.component.scss' ]
12})
13export class ActorAvatarInfoComponent implements OnInit {
14 @ViewChild('avatarfileInput') avatarfileInput: ElementRef<HTMLInputElement>
15
16 @Input() actor: VideoChannel | Account
17
18 @Output() avatarChange = new EventEmitter<FormData>()
19
20 maxSizeText: string
21
22 private serverConfig: ServerConfig
23 private bytesPipe: BytesPipe
24
25 constructor (
26 private serverService: ServerService,
27 private notifier: Notifier,
28 private i18n: I18n
29 ) {
30 this.bytesPipe = new BytesPipe()
31 this.maxSizeText = this.i18n('max size')
32 }
33
34 ngOnInit (): void {
35 this.serverConfig = this.serverService.getTmpConfig()
36 this.serverService.getConfig()
37 .subscribe(config => this.serverConfig = config)
38 }
39
40 onAvatarChange () {
41 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
42 if (avatarfile.size > this.maxAvatarSize) {
43 this.notifier.error('Error', 'This image is too large.')
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 () {
54 return this.serverConfig.avatar.file.size.max
55 }
56
57 get maxAvatarSizeInBytes () {
58 return this.bytesPipe.transform(this.maxAvatarSize)
59 }
60
61 get avatarExtensions () {
62 return this.serverConfig.avatar.file.extensions.join(', ')
63 }
64}