]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/account/account-settings/account-settings.component.ts
Add avatar max size limit
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-settings / account-settings.component.ts
CommitLineData
c5911fd3
C
1import { Component, OnInit, ViewChild } from '@angular/core'
2import { NotificationsService } from 'angular2-notifications'
c30745f3 3import { AuthService } from '../../core'
01de67b9
C
4import { ServerService } from '../../core/server'
5import { User } from '../../shared'
c5911fd3 6import { UserService } from '../../shared/users'
c30745f3
C
7
8@Component({
9 selector: 'my-account-settings',
10 templateUrl: './account-settings.component.html',
11 styleUrls: [ './account-settings.component.scss' ]
12})
13export class AccountSettingsComponent implements OnInit {
c5911fd3
C
14 @ViewChild('avatarfileInput') avatarfileInput
15
c30745f3
C
16 user: User = null
17
c5911fd3
C
18 constructor (
19 private userService: UserService,
20 private authService: AuthService,
01de67b9 21 private serverService: ServerService,
c5911fd3
C
22 private notificationsService: NotificationsService
23 ) {}
c30745f3
C
24
25 ngOnInit () {
26 this.user = this.authService.getUser()
27 }
2295ce6c 28
c5911fd3
C
29 getAvatarUrl () {
30 return this.user.getAvatarUrl()
31 }
32
33 changeAvatar () {
34 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
35
36 const formData = new FormData()
37 formData.append('avatarfile', avatarfile)
38
39 this.userService.changeAvatar(formData)
40 .subscribe(
41 data => {
42 this.notificationsService.success('Success', 'Avatar changed.')
43
44 this.user.account.avatar = data.avatar
45 },
46
47 err => this.notificationsService.error('Error', err.message)
48 )
2295ce6c 49 }
01de67b9
C
50
51 get maxAvatarSize () {
52 return this.serverService.getConfig().avatar.file.size.max
53 }
54
55 get avatarExtensions () {
56 return this.serverService.getConfig().avatar.file.extensions.join(',')
57 }
c30745f3 58}