]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/account/actor-avatar-info.component.ts
Remove angular pipes module
[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'
e61151b0 4import { I18n } from '@ngx-translate/i18n-polyfill'
67ed6552 5import { ServerConfig } from '@shared/models'
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})
ba430d75 12export class ActorAvatarInfoComponent implements OnInit {
2f5d2ec5 13 @ViewChild('avatarfileInput') avatarfileInput: ElementRef<HTMLInputElement>
52d9f792
C
14
15 @Input() actor: VideoChannel | Account
16
17 @Output() avatarChange = new EventEmitter<FormData>()
18
e61151b0
RK
19 maxSizeText: string
20
ba430d75 21 private serverConfig: ServerConfig
e61151b0 22 private bytesPipe: BytesPipe
ba430d75 23
52d9f792 24 constructor (
52d9f792 25 private serverService: ServerService,
e61151b0
RK
26 private notifier: Notifier,
27 private i18n: I18n
28 ) {
29 this.bytesPipe = new BytesPipe()
30 this.maxSizeText = this.i18n('max size')
31 }
52d9f792 32
ba430d75
C
33 ngOnInit (): void {
34 this.serverConfig = this.serverService.getTmpConfig()
35 this.serverService.getConfig()
36 .subscribe(config => this.serverConfig = config)
37 }
38
52d9f792
C
39 onAvatarChange () {
40 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
41 if (avatarfile.size > this.maxAvatarSize) {
f8b2c1b4 42 this.notifier.error('Error', 'This image is too large.')
52d9f792
C
43 return
44 }
45
46 const formData = new FormData()
47 formData.append('avatarfile', avatarfile)
48
49 this.avatarChange.emit(formData)
50 }
51
52 get maxAvatarSize () {
ba430d75 53 return this.serverConfig.avatar.file.size.max
52d9f792
C
54 }
55
e61151b0
RK
56 get maxAvatarSizeInBytes () {
57 return this.bytesPipe.transform(this.maxAvatarSize)
58 }
59
52d9f792 60 get avatarExtensions () {
482fa503 61 return this.serverConfig.avatar.file.extensions.join(', ')
52d9f792
C
62 }
63}