]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/account/actor-avatar-info.component.ts
fix user preferences column width for notifications table (#3352)
[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'
b4c3c51d 3import { getBytes } from '@root-helpers/bytes'
67ed6552 4import { ServerConfig } from '@shared/models'
b4c3c51d
C
5import { VideoChannel } from '../video-channel/video-channel.model'
6import { Account } from '../account/account.model'
52d9f792
C
7
8@Component({
9 selector: 'my-actor-avatar-info',
10 templateUrl: './actor-avatar-info.component.html',
11 styleUrls: [ './actor-avatar-info.component.scss' ]
12})
ba430d75 13export class ActorAvatarInfoComponent implements OnInit {
2f5d2ec5 14 @ViewChild('avatarfileInput') avatarfileInput: ElementRef<HTMLInputElement>
52d9f792
C
15
16 @Input() actor: VideoChannel | Account
17
18 @Output() avatarChange = new EventEmitter<FormData>()
19
e61151b0
RK
20 maxSizeText: string
21
ba430d75
C
22 private serverConfig: ServerConfig
23
52d9f792 24 constructor (
52d9f792 25 private serverService: ServerService,
66357162 26 private notifier: Notifier
e61151b0 27 ) {
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 54 get maxAvatarSizeInBytes () {
b4c3c51d 55 return getBytes(this.maxAvatarSize)
e61151b0
RK
56 }
57
52d9f792 58 get avatarExtensions () {
482fa503 59 return this.serverConfig.avatar.file.extensions.join(', ')
52d9f792
C
60 }
61}