]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-applications/my-account-applications.component.ts
Move to sass module
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-applications / my-account-applications.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { AuthService, Notifier, ConfirmService, ScopedTokensService } from '@app/core'
3 import { VideoService } from '@app/shared/shared-main'
4 import { FeedFormat } from '@shared/models'
5 import { ScopedToken } from '@shared/models/users/user-scoped-token'
6 import { environment } from '../../../environments/environment'
7
8 @Component({
9 selector: 'my-account-applications',
10 templateUrl: './my-account-applications.component.html',
11 styleUrls: [ './my-account-applications.component.scss' ]
12 })
13 export class MyAccountApplicationsComponent implements OnInit {
14 feedUrl: string
15 feedToken: string
16
17 private baseURL = environment.originServerUrl || window.location.origin
18
19 constructor (
20 private authService: AuthService,
21 private scopedTokensService: ScopedTokensService,
22 private videoService: VideoService,
23 private notifier: Notifier,
24 private confirmService: ConfirmService
25 ) {}
26
27 ngOnInit () {
28 this.feedUrl = this.baseURL
29 this.scopedTokensService.getScopedTokens()
30 .subscribe(
31 tokens => this.regenApplications(tokens),
32
33 err => {
34 this.notifier.error(err.message)
35 }
36 )
37 }
38
39 async renewToken () {
40 const res = await this.confirmService.confirm(
41 $localize`Renewing the token will disallow previously configured clients from retrieving the feed until they use the new token. Proceed?`,
42 $localize`Renew token`
43 )
44 if (res === false) return
45
46 this.scopedTokensService.renewScopedTokens().subscribe(
47 tokens => {
48 this.regenApplications(tokens)
49 this.notifier.success($localize`Token renewed. Update your client configuration accordingly.`)
50 },
51
52 err => {
53 this.notifier.error(err.message)
54 }
55 )
56
57 }
58
59 private regenApplications (tokens: ScopedToken) {
60 const user = this.authService.getUser()
61 const feeds = this.videoService.getVideoSubscriptionFeedUrls(user.account.id, tokens.feedToken)
62 this.feedUrl = this.baseURL + feeds.find(f => f.format === FeedFormat.RSS).url
63 this.feedToken = tokens.feedToken
64 }
65 }