1 import { Component, OnInit } from '@angular/core'
2 import { AuthService, ConfirmService, Notifier, ScopedTokensService } from '@app/core'
3 import { VideoService } from '@app/shared/shared-main'
4 import { FeedFormat } from '@shared/models'
5 import { ScopedToken } from '@shared/models/users/user-scoped-token'
6 import { environment } from '../../../environments/environment'
9 selector: 'my-account-applications',
10 templateUrl: './my-account-applications.component.html',
11 styleUrls: [ './my-account-applications.component.scss' ]
13 export class MyAccountApplicationsComponent implements OnInit {
17 private baseURL = environment.originServerUrl || window.location.origin
20 private authService: AuthService,
21 private scopedTokensService: ScopedTokensService,
22 private videoService: VideoService,
23 private notifier: Notifier,
24 private confirmService: ConfirmService
28 this.feedUrl = this.baseURL
29 this.scopedTokensService.getScopedTokens()
31 next: tokens => this.regenApplications(tokens),
33 error: err => this.notifier.error(err.message)
38 const res = await this.confirmService.confirm(
39 $localize`Renewing the token will disallow previously configured clients from retrieving the feed until they use the new token. Proceed?`,
40 $localize`Renew token`
42 if (res === false) return
44 this.scopedTokensService.renewScopedTokens()
47 this.regenApplications(tokens)
48 this.notifier.success($localize`Token renewed. Update your client configuration accordingly.`)
51 error: err => this.notifier.error(err.message)
55 private regenApplications (tokens: ScopedToken) {
56 const user = this.authService.getUser()
57 const feeds = this.videoService.getVideoSubscriptionFeedUrls(user.account.id, tokens.feedToken)
58 this.feedUrl = this.baseURL + feeds.find(f => f.format === FeedFormat.RSS).url
59 this.feedToken = tokens.feedToken