]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import { Component, OnInit } from '@angular/core' | |
3 | import { AuthService, Notifier, ConfirmService, ScopedTokensService } from '@app/core' | |
4 | import { VideoService } from '@app/shared/shared-main' | |
5 | import { FeedFormat } from '@shared/models' | |
6 | import { ScopedToken } from '@shared/models/users/user-scoped-token' | |
7 | import { environment } from '../../../environments/environment' | |
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 | ||
18 | private baseURL = environment.originServerUrl | |
19 | ||
20 | constructor ( | |
21 | private authService: AuthService, | |
22 | private scopedTokensService: ScopedTokensService, | |
23 | private videoService: VideoService, | |
24 | private notifier: Notifier, | |
25 | private confirmService: ConfirmService | |
26 | ) {} | |
27 | ||
28 | ngOnInit () { | |
29 | this.feedUrl = this.baseURL | |
30 | this.scopedTokensService.getScopedTokens() | |
31 | .subscribe( | |
32 | tokens => this.regenApplications(tokens), | |
33 | ||
34 | err => { | |
35 | this.notifier.error(err.message) | |
36 | } | |
37 | ) | |
38 | } | |
39 | ||
40 | async renewToken () { | |
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 | ) | |
45 | if (res === false) return | |
46 | ||
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 | |
65 | } | |
66 | } |