]>
Commit | Line | Data |
---|---|---|
afff310e | 1 | import { Component, OnInit } from '@angular/core' |
1378c0d3 | 2 | import { AuthService, ConfirmService, Notifier, ScopedTokensService } from '@app/core' |
afff310e RK |
3 | import { VideoService } from '@app/shared/shared-main' |
4 | import { FeedFormat } from '@shared/models' | |
5beb89f2 RK |
5 | import { ScopedToken } from '@shared/models/users/user-scoped-token' |
6 | import { environment } from '../../../environments/environment' | |
afff310e RK |
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 | ||
04b2996b | 17 | private baseURL = environment.originServerUrl || window.location.origin |
afff310e RK |
18 | |
19 | constructor ( | |
20 | private authService: AuthService, | |
5beb89f2 | 21 | private scopedTokensService: ScopedTokensService, |
afff310e RK |
22 | private videoService: VideoService, |
23 | private notifier: Notifier, | |
24 | private confirmService: ConfirmService | |
25 | ) {} | |
26 | ||
27 | ngOnInit () { | |
28 | this.feedUrl = this.baseURL | |
5beb89f2 | 29 | this.scopedTokensService.getScopedTokens() |
1378c0d3 C |
30 | .subscribe({ |
31 | next: tokens => this.regenApplications(tokens), | |
afff310e | 32 | |
1378c0d3 C |
33 | error: err => this.notifier.error(err.message) |
34 | }) | |
afff310e RK |
35 | } |
36 | ||
37 | async renewToken () { | |
5beb89f2 | 38 | const res = await this.confirmService.confirm( |
9df52d66 | 39 | // eslint-disable-next-line max-len |
5beb89f2 RK |
40 | $localize`Renewing the token will disallow previously configured clients from retrieving the feed until they use the new token. Proceed?`, |
41 | $localize`Renew token` | |
42 | ) | |
afff310e RK |
43 | if (res === false) return |
44 | ||
1378c0d3 C |
45 | this.scopedTokensService.renewScopedTokens() |
46 | .subscribe({ | |
47 | next: tokens => { | |
48 | this.regenApplications(tokens) | |
49 | this.notifier.success($localize`Token renewed. Update your client configuration accordingly.`) | |
50 | }, | |
5beb89f2 | 51 | |
1378c0d3 C |
52 | error: err => this.notifier.error(err.message) |
53 | }) | |
5beb89f2 RK |
54 | } |
55 | ||
56 | private regenApplications (tokens: ScopedToken) { | |
57 | const user = this.authService.getUser() | |
58 | const feeds = this.videoService.getVideoSubscriptionFeedUrls(user.account.id, tokens.feedToken) | |
59 | this.feedUrl = this.baseURL + feeds.find(f => f.format === FeedFormat.RSS).url | |
60 | this.feedToken = tokens.feedToken | |
afff310e RK |
61 | } |
62 | } |