diff options
Diffstat (limited to 'client/src/app/+my-account/my-account-applications/my-account-applications.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-applications/my-account-applications.component.ts | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts b/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts new file mode 100644 index 000000000..c3f09dfe3 --- /dev/null +++ b/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts | |||
@@ -0,0 +1,57 @@ | |||
1 | |||
2 | import { Component, OnInit } from '@angular/core' | ||
3 | import { AuthService, Notifier, ConfirmService } from '@app/core' | ||
4 | import { VideoService } from '@app/shared/shared-main' | ||
5 | import { FeedFormat } from '@shared/models' | ||
6 | import { Subject, merge } from 'rxjs' | ||
7 | import { debounceTime } from 'rxjs/operators' | ||
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 = window.location.protocol + '//' + window.location.host | ||
19 | private tokenStream = new Subject() | ||
20 | |||
21 | constructor ( | ||
22 | private authService: AuthService, | ||
23 | private videoService: VideoService, | ||
24 | private notifier: Notifier, | ||
25 | private confirmService: ConfirmService | ||
26 | ) {} | ||
27 | |||
28 | ngOnInit () { | ||
29 | this.feedUrl = this.baseURL | ||
30 | |||
31 | merge( | ||
32 | this.tokenStream, | ||
33 | this.authService.userInformationLoaded | ||
34 | ).pipe(debounceTime(400)) | ||
35 | .subscribe( | ||
36 | _ => { | ||
37 | const user = this.authService.getUser() | ||
38 | this.videoService.getVideoSubscriptionFeedUrls(user.account.id) | ||
39 | .then(feeds => this.feedUrl = this.baseURL + feeds.find(f => f.format === FeedFormat.RSS).url) | ||
40 | .then(_ => this.authService.getScopedTokens().then(tokens => this.feedToken = tokens.feedToken)) | ||
41 | }, | ||
42 | |||
43 | err => { | ||
44 | this.notifier.error(err.message) | ||
45 | } | ||
46 | ) | ||
47 | } | ||
48 | |||
49 | async renewToken () { | ||
50 | const res = await this.confirmService.confirm('Renewing the token will disallow previously configured clients from retrieving the feed until they use the new token. Proceed?', 'Renew token') | ||
51 | if (res === false) return | ||
52 | |||
53 | await this.authService.renewScopedTokens() | ||
54 | this.notifier.success('Token renewed. Update your client configuration accordingly.') | ||
55 | this.tokenStream.next() | ||
56 | } | ||
57 | } | ||