]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/account/actor-avatar-info.component.ts
5daa54cb59c208806d156350a3c8a02b3d0ab253
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / actor-avatar-info.component.ts
1 import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { Notifier, ServerService } from '@app/core'
3 import { getBytes } from '@root-helpers/bytes'
4 import { ServerConfig } from '@shared/models'
5 import { VideoChannel } from '../video-channel/video-channel.model'
6 import { Account } from '../account/account.model'
7
8 @Component({
9 selector: 'my-actor-avatar-info',
10 templateUrl: './actor-avatar-info.component.html',
11 styleUrls: [ './actor-avatar-info.component.scss' ]
12 })
13 export 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
24 constructor (
25 private serverService: ServerService,
26 private notifier: Notifier
27 ) {
28 this.maxSizeText = $localize`max size`
29 }
30
31 ngOnInit (): void {
32 this.serverConfig = this.serverService.getTmpConfig()
33 this.serverService.getConfig()
34 .subscribe(config => this.serverConfig = config)
35 }
36
37 onAvatarChange () {
38 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
39 if (avatarfile.size > this.maxAvatarSize) {
40 this.notifier.error('Error', 'This image is too large.')
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 () {
51 return this.serverConfig.avatar.file.size.max
52 }
53
54 get maxAvatarSizeInBytes () {
55 return getBytes(this.maxAvatarSize)
56 }
57
58 get avatarExtensions () {
59 return this.serverConfig.avatar.file.extensions.join(', ')
60 }
61 }