]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/account/actor-avatar-info.component.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / actor-avatar-info.component.ts
CommitLineData
67ed6552
C
1import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2import { Notifier, ServerService } from '@app/core'
94676e63 3import { Account, BytesPipe, VideoChannel } from '@app/shared/shared-main'
67ed6552 4import { ServerConfig } from '@shared/models'
52d9f792
C
5
6@Component({
7 selector: 'my-actor-avatar-info',
8 templateUrl: './actor-avatar-info.component.html',
9 styleUrls: [ './actor-avatar-info.component.scss' ]
10})
ba430d75 11export class ActorAvatarInfoComponent implements OnInit {
2f5d2ec5 12 @ViewChild('avatarfileInput') avatarfileInput: ElementRef<HTMLInputElement>
52d9f792
C
13
14 @Input() actor: VideoChannel | Account
15
16 @Output() avatarChange = new EventEmitter<FormData>()
17
e61151b0
RK
18 maxSizeText: string
19
ba430d75 20 private serverConfig: ServerConfig
e61151b0 21 private bytesPipe: BytesPipe
ba430d75 22
52d9f792 23 constructor (
52d9f792 24 private serverService: ServerService,
66357162 25 private notifier: Notifier
e61151b0
RK
26 ) {
27 this.bytesPipe = new BytesPipe()
66357162 28 this.maxSizeText = $localize`max size`
e61151b0 29 }
52d9f792 30
ba430d75
C
31 ngOnInit (): void {
32 this.serverConfig = this.serverService.getTmpConfig()
33 this.serverService.getConfig()
34 .subscribe(config => this.serverConfig = config)
35 }
36
52d9f792
C
37 onAvatarChange () {
38 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
39 if (avatarfile.size > this.maxAvatarSize) {
f8b2c1b4 40 this.notifier.error('Error', 'This image is too large.')
52d9f792
C
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 () {
ba430d75 51 return this.serverConfig.avatar.file.size.max
52d9f792
C
52 }
53
e61151b0
RK
54 get maxAvatarSizeInBytes () {
55 return this.bytesPipe.transform(this.maxAvatarSize)
56 }
57
52d9f792 58 get avatarExtensions () {
482fa503 59 return this.serverConfig.avatar.file.extensions.join(', ')
52d9f792
C
60 }
61}