aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+my-account/my-account-applications
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-11-09 16:25:27 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 11:07:56 +0100
commit5beb89f223539f1e415a976ff104f772526b4d20 (patch)
tree2164677d16a2965d63499e249aa75ab0e06e3a6c /client/src/app/+my-account/my-account-applications
parentafff310e50f2fa8419bb4242470cbde46ab54463 (diff)
downloadPeerTube-5beb89f223539f1e415a976ff104f772526b4d20.tar.gz
PeerTube-5beb89f223539f1e415a976ff104f772526b4d20.tar.zst
PeerTube-5beb89f223539f1e415a976ff104f772526b4d20.zip
refactor scoped token service
Diffstat (limited to 'client/src/app/+my-account/my-account-applications')
-rw-r--r--client/src/app/+my-account/my-account-applications/my-account-applications.component.html4
-rw-r--r--client/src/app/+my-account/my-account-applications/my-account-applications.component.ts59
2 files changed, 36 insertions, 27 deletions
diff --git a/client/src/app/+my-account/my-account-applications/my-account-applications.component.html b/client/src/app/+my-account/my-account-applications/my-account-applications.component.html
index 62e2cb59b..53a9c91ac 100644
--- a/client/src/app/+my-account/my-account-applications/my-account-applications.component.html
+++ b/client/src/app/+my-account/my-account-applications/my-account-applications.component.html
@@ -7,8 +7,8 @@
7 <div class="form-group col-12 col-lg-4 col-xl-3"> 7 <div class="form-group col-12 col-lg-4 col-xl-3">
8 <h2 i18n class="applications-title">SUBSCRIPTION FEED</h2> 8 <h2 i18n class="applications-title">SUBSCRIPTION FEED</h2>
9 <div i18n class="applications-description"> 9 <div i18n class="applications-description">
10 Used to retrieve the list of videos of the creators 10 Use third-party feed aggregators to retrieve the list of videos from
11 you subscribed to from outside PeerTube 11 channels you subscribed to. Make sure to keep your token private.
12 </div> 12 </div>
13 </div> 13 </div>
14 14
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
index c3f09dfe3..233e42c83 100644
--- 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
@@ -1,10 +1,10 @@
1 1
2import { Component, OnInit } from '@angular/core' 2import { Component, OnInit } from '@angular/core'
3import { AuthService, Notifier, ConfirmService } from '@app/core' 3import { AuthService, Notifier, ConfirmService, ScopedTokensService } from '@app/core'
4import { VideoService } from '@app/shared/shared-main' 4import { VideoService } from '@app/shared/shared-main'
5import { FeedFormat } from '@shared/models' 5import { FeedFormat } from '@shared/models'
6import { Subject, merge } from 'rxjs' 6import { ScopedToken } from '@shared/models/users/user-scoped-token'
7import { debounceTime } from 'rxjs/operators' 7import { environment } from '../../../environments/environment'
8 8
9@Component({ 9@Component({
10 selector: 'my-account-applications', 10 selector: 'my-account-applications',
@@ -15,11 +15,11 @@ export class MyAccountApplicationsComponent implements OnInit {
15 feedUrl: string 15 feedUrl: string
16 feedToken: string 16 feedToken: string
17 17
18 private baseURL = window.location.protocol + '//' + window.location.host 18 private baseURL = environment.originServerUrl
19 private tokenStream = new Subject()
20 19
21 constructor ( 20 constructor (
22 private authService: AuthService, 21 private authService: AuthService,
22 private scopedTokensService: ScopedTokensService,
23 private videoService: VideoService, 23 private videoService: VideoService,
24 private notifier: Notifier, 24 private notifier: Notifier,
25 private confirmService: ConfirmService 25 private confirmService: ConfirmService
@@ -27,31 +27,40 @@ export class MyAccountApplicationsComponent implements OnInit {
27 27
28 ngOnInit () { 28 ngOnInit () {
29 this.feedUrl = this.baseURL 29 this.feedUrl = this.baseURL
30 this.scopedTokensService.getScopedTokens()
31 .subscribe(
32 tokens => this.regenApplications(tokens),
30 33
31 merge( 34 err => {
32 this.tokenStream, 35 this.notifier.error(err.message)
33 this.authService.userInformationLoaded 36 }
34 ).pipe(debounceTime(400)) 37 )
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 } 38 }
48 39
49 async renewToken () { 40 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') 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 )
51 if (res === false) return 45 if (res === false) return
52 46
53 await this.authService.renewScopedTokens() 47 this.scopedTokensService.renewScopedTokens().subscribe(
54 this.notifier.success('Token renewed. Update your client configuration accordingly.') 48 tokens => {
55 this.tokenStream.next() 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
56 } 65 }
57} 66}