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