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