diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-11-09 16:25:27 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-25 11:07:56 +0100 |
commit | 5beb89f223539f1e415a976ff104f772526b4d20 (patch) | |
tree | 2164677d16a2965d63499e249aa75ab0e06e3a6c /client/src/app/+my-account | |
parent | afff310e50f2fa8419bb4242470cbde46ab54463 (diff) | |
download | PeerTube-5beb89f223539f1e415a976ff104f772526b4d20.tar.gz PeerTube-5beb89f223539f1e415a976ff104f772526b4d20.tar.zst PeerTube-5beb89f223539f1e415a976ff104f772526b4d20.zip |
refactor scoped token service
Diffstat (limited to 'client/src/app/+my-account')
4 files changed, 43 insertions, 34 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 | ||
2 | import { Component, OnInit } from '@angular/core' | 2 | import { Component, OnInit } from '@angular/core' |
3 | import { AuthService, Notifier, ConfirmService } from '@app/core' | 3 | import { AuthService, Notifier, ConfirmService, ScopedTokensService } from '@app/core' |
4 | import { VideoService } from '@app/shared/shared-main' | 4 | import { VideoService } from '@app/shared/shared-main' |
5 | import { FeedFormat } from '@shared/models' | 5 | import { FeedFormat } from '@shared/models' |
6 | import { Subject, merge } from 'rxjs' | 6 | import { ScopedToken } from '@shared/models/users/user-scoped-token' |
7 | import { debounceTime } from 'rxjs/operators' | 7 | import { 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 | } |
diff --git a/client/src/app/+my-account/my-account.component.ts b/client/src/app/+my-account/my-account.component.ts index 12966aebb..eaf8a72e9 100644 --- a/client/src/app/+my-account/my-account.component.ts +++ b/client/src/app/+my-account/my-account.component.ts | |||
@@ -41,11 +41,6 @@ export class MyAccountComponent implements OnInit { | |||
41 | label: $localize`Abuse reports`, | 41 | label: $localize`Abuse reports`, |
42 | routerLink: '/my-account/abuses', | 42 | routerLink: '/my-account/abuses', |
43 | iconName: 'flag' | 43 | iconName: 'flag' |
44 | }, | ||
45 | { | ||
46 | label: $localize`Applications`, | ||
47 | routerLink: '/my-account/applications', | ||
48 | iconName: 'codesandbox' | ||
49 | } | 44 | } |
50 | ] | 45 | ] |
51 | } | 46 | } |
@@ -61,6 +56,11 @@ export class MyAccountComponent implements OnInit { | |||
61 | routerLink: '/my-account/notifications' | 56 | routerLink: '/my-account/notifications' |
62 | }, | 57 | }, |
63 | 58 | ||
59 | { | ||
60 | label: $localize`Applications`, | ||
61 | routerLink: '/my-account/applications' | ||
62 | }, | ||
63 | |||
64 | moderationEntries | 64 | moderationEntries |
65 | ] | 65 | ] |
66 | } | 66 | } |
diff --git a/client/src/app/+my-account/my-account.module.ts b/client/src/app/+my-account/my-account.module.ts index 70bf58aae..076864563 100644 --- a/client/src/app/+my-account/my-account.module.ts +++ b/client/src/app/+my-account/my-account.module.ts | |||
@@ -20,8 +20,8 @@ import { MyAccountDangerZoneComponent } from './my-account-settings/my-account-d | |||
20 | import { MyAccountNotificationPreferencesComponent } from './my-account-settings/my-account-notification-preferences' | 20 | import { MyAccountNotificationPreferencesComponent } from './my-account-settings/my-account-notification-preferences' |
21 | import { MyAccountProfileComponent } from './my-account-settings/my-account-profile/my-account-profile.component' | 21 | import { MyAccountProfileComponent } from './my-account-settings/my-account-profile/my-account-profile.component' |
22 | import { MyAccountSettingsComponent } from './my-account-settings/my-account-settings.component' | 22 | import { MyAccountSettingsComponent } from './my-account-settings/my-account-settings.component' |
23 | import { MyAccountApplicationsComponent } from './my-account-applications/my-account-applications.component' | ||
23 | import { MyAccountComponent } from './my-account.component' | 24 | import { MyAccountComponent } from './my-account.component' |
24 | import { VideoChangeOwnershipComponent } from './my-account-applications/my-account-applications.component' | ||
25 | 25 | ||
26 | @NgModule({ | 26 | @NgModule({ |
27 | imports: [ | 27 | imports: [ |
@@ -46,13 +46,13 @@ import { VideoChangeOwnershipComponent } from './my-account-applications/my-acco | |||
46 | MyAccountChangePasswordComponent, | 46 | MyAccountChangePasswordComponent, |
47 | MyAccountProfileComponent, | 47 | MyAccountProfileComponent, |
48 | MyAccountChangeEmailComponent, | 48 | MyAccountChangeEmailComponent, |
49 | MyAccountApplicationsComponent, | ||
49 | 50 | ||
50 | MyAccountDangerZoneComponent, | 51 | MyAccountDangerZoneComponent, |
51 | MyAccountBlocklistComponent, | 52 | MyAccountBlocklistComponent, |
52 | MyAccountAbusesListComponent, | 53 | MyAccountAbusesListComponent, |
53 | MyAccountServerBlocklistComponent, | 54 | MyAccountServerBlocklistComponent, |
54 | MyAccountNotificationsComponent, | 55 | MyAccountNotificationsComponent, |
55 | MyAccountNotificationPreferencesComponent, | ||
56 | MyAccountNotificationPreferencesComponent | 56 | MyAccountNotificationPreferencesComponent |
57 | ], | 57 | ], |
58 | 58 | ||