diff options
Diffstat (limited to 'client/src/app/core')
-rw-r--r-- | client/src/app/core/auth/auth.service.ts | 111 | ||||
-rw-r--r-- | client/src/app/core/confirm/confirm.service.ts | 9 | ||||
-rw-r--r-- | client/src/app/core/routing/preload-selected-modules-list.ts | 11 | ||||
-rw-r--r-- | client/src/app/core/server/server.service.ts | 14 |
4 files changed, 71 insertions, 74 deletions
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index 6223cde6d..4b388d7be 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts | |||
@@ -1,14 +1,9 @@ | |||
1 | import { Observable, ReplaySubject, Subject, throwError as observableThrowError } from 'rxjs' | ||
2 | import { catchError, map, mergeMap, tap } from 'rxjs/operators' | ||
1 | import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http' | 3 | import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http' |
2 | import { Injectable } from '@angular/core' | 4 | import { Injectable } from '@angular/core' |
3 | import { Router } from '@angular/router' | 5 | import { Router } from '@angular/router' |
4 | import { NotificationsService } from 'angular2-notifications' | 6 | import { NotificationsService } from 'angular2-notifications' |
5 | import 'rxjs/add/observable/throw' | ||
6 | import 'rxjs/add/operator/do' | ||
7 | import 'rxjs/add/operator/map' | ||
8 | import 'rxjs/add/operator/mergeMap' | ||
9 | import { Observable } from 'rxjs/Observable' | ||
10 | import { ReplaySubject } from 'rxjs/ReplaySubject' | ||
11 | import { Subject } from 'rxjs/Subject' | ||
12 | import { OAuthClientLocal, User as UserServerModel, UserRefreshToken } from '../../../../../shared' | 7 | import { OAuthClientLocal, User as UserServerModel, UserRefreshToken } from '../../../../../shared' |
13 | import { User } from '../../../../../shared/models/users' | 8 | import { User } from '../../../../../shared/models/users' |
14 | import { UserLogin } from '../../../../../shared/models/users/user-login.model' | 9 | import { UserLogin } from '../../../../../shared/models/users/user-login.model' |
@@ -46,7 +41,7 @@ export class AuthService { | |||
46 | private notificationsService: NotificationsService, | 41 | private notificationsService: NotificationsService, |
47 | private restExtractor: RestExtractor, | 42 | private restExtractor: RestExtractor, |
48 | private router: Router | 43 | private router: Router |
49 | ) { | 44 | ) { |
50 | this.loginChanged = new Subject<AuthStatus>() | 45 | this.loginChanged = new Subject<AuthStatus>() |
51 | this.loginChangedSource = this.loginChanged.asObservable() | 46 | this.loginChangedSource = this.loginChanged.asObservable() |
52 | 47 | ||
@@ -58,28 +53,28 @@ export class AuthService { | |||
58 | // Fetch the client_id/client_secret | 53 | // Fetch the client_id/client_secret |
59 | // FIXME: save in local storage? | 54 | // FIXME: save in local storage? |
60 | this.http.get<OAuthClientLocal>(AuthService.BASE_CLIENT_URL) | 55 | this.http.get<OAuthClientLocal>(AuthService.BASE_CLIENT_URL) |
61 | .catch(res => this.restExtractor.handleError(res)) | 56 | .pipe(catchError(res => this.restExtractor.handleError(res))) |
62 | .subscribe( | 57 | .subscribe( |
63 | res => { | 58 | res => { |
64 | this.clientId = res.client_id | 59 | this.clientId = res.client_id |
65 | this.clientSecret = res.client_secret | 60 | this.clientSecret = res.client_secret |
66 | console.log('Client credentials loaded.') | 61 | console.log('Client credentials loaded.') |
67 | }, | 62 | }, |
68 | 63 | ||
69 | error => { | 64 | error => { |
70 | let errorMessage = error.message | 65 | let errorMessage = error.message |
71 | 66 | ||
72 | if (error.status === 403) { | 67 | if (error.status === 403) { |
73 | errorMessage = `Cannot retrieve OAuth Client credentials: ${error.text}. \n` | 68 | errorMessage = `Cannot retrieve OAuth Client credentials: ${error.text}. \n` |
74 | errorMessage += 'Ensure you have correctly configured PeerTube (config/ directory), ' + | 69 | errorMessage += 'Ensure you have correctly configured PeerTube (config/ directory), ' + |
75 | 'in particular the "webserver" section.' | 70 | 'in particular the "webserver" section.' |
76 | } | 71 | } |
77 | 72 | ||
78 | // We put a bigger timeout | 73 | // We put a bigger timeout |
79 | // This is an important message | 74 | // This is an important message |
80 | this.notificationsService.error('Error', errorMessage, { timeOut: 7000 }) | 75 | this.notificationsService.error('Error', errorMessage, { timeOut: 7000 }) |
81 | } | 76 | } |
82 | ) | 77 | ) |
83 | } | 78 | } |
84 | 79 | ||
85 | getRefreshToken () { | 80 | getRefreshToken () { |
@@ -129,10 +124,12 @@ export class AuthService { | |||
129 | 124 | ||
130 | const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') | 125 | const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') |
131 | return this.http.post<UserLogin>(AuthService.BASE_TOKEN_URL, body.toString(), { headers }) | 126 | return this.http.post<UserLogin>(AuthService.BASE_TOKEN_URL, body.toString(), { headers }) |
132 | .map(res => Object.assign(res, { username })) | 127 | .pipe( |
133 | .flatMap(res => this.mergeUserInformation(res)) | 128 | map(res => Object.assign(res, { username })), |
134 | .map(res => this.handleLogin(res)) | 129 | mergeMap(res => this.mergeUserInformation(res)), |
135 | .catch(res => this.restExtractor.handleError(res)) | 130 | map(res => this.handleLogin(res)), |
131 | catchError(res => this.restExtractor.handleError(res)) | ||
132 | ) | ||
136 | } | 133 | } |
137 | 134 | ||
138 | logout () { | 135 | logout () { |
@@ -161,20 +158,22 @@ export class AuthService { | |||
161 | const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') | 158 | const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') |
162 | 159 | ||
163 | this.refreshingTokenObservable = this.http.post<UserRefreshToken>(AuthService.BASE_TOKEN_URL, body, { headers }) | 160 | this.refreshingTokenObservable = this.http.post<UserRefreshToken>(AuthService.BASE_TOKEN_URL, body, { headers }) |
164 | .map(res => this.handleRefreshToken(res)) | 161 | .pipe( |
165 | .do(() => this.refreshingTokenObservable = null) | 162 | map(res => this.handleRefreshToken(res)), |
166 | .catch(err => { | 163 | tap(() => this.refreshingTokenObservable = null), |
167 | this.refreshingTokenObservable = null | 164 | catchError(err => { |
168 | 165 | this.refreshingTokenObservable = null | |
169 | console.error(err) | 166 | |
170 | console.log('Cannot refresh token -> logout...') | 167 | console.error(err) |
171 | this.logout() | 168 | console.log('Cannot refresh token -> logout...') |
172 | this.router.navigate([ '/login' ]) | 169 | this.logout() |
173 | 170 | this.router.navigate([ '/login' ]) | |
174 | return Observable.throw({ | 171 | |
175 | error: 'You need to reconnect.' | 172 | return observableThrowError({ |
176 | }) | 173 | error: 'You need to reconnect.' |
177 | }) | 174 | }) |
175 | }) | ||
176 | ) | ||
178 | 177 | ||
179 | return this.refreshingTokenObservable | 178 | return this.refreshingTokenObservable |
180 | } | 179 | } |
@@ -188,14 +187,14 @@ export class AuthService { | |||
188 | } | 187 | } |
189 | 188 | ||
190 | this.mergeUserInformation(obj) | 189 | this.mergeUserInformation(obj) |
191 | .subscribe( | 190 | .subscribe( |
192 | res => { | 191 | res => { |
193 | this.user.patch(res) | 192 | this.user.patch(res) |
194 | this.user.save() | 193 | this.user.save() |
195 | 194 | ||
196 | this.userInformationLoaded.next(true) | 195 | this.userInformationLoaded.next(true) |
197 | } | 196 | } |
198 | ) | 197 | ) |
199 | } | 198 | } |
200 | 199 | ||
201 | private mergeUserInformation (obj: UserLoginWithUsername): Observable<UserLoginWithUserInformation> { | 200 | private mergeUserInformation (obj: UserLoginWithUsername): Observable<UserLoginWithUserInformation> { |
@@ -203,7 +202,7 @@ export class AuthService { | |||
203 | const headers = new HttpHeaders().set('Authorization', `${obj.token_type} ${obj.access_token}`) | 202 | const headers = new HttpHeaders().set('Authorization', `${obj.token_type} ${obj.access_token}`) |
204 | 203 | ||
205 | return this.http.get<UserServerModel>(AuthService.BASE_USER_INFORMATION_URL, { headers }) | 204 | return this.http.get<UserServerModel>(AuthService.BASE_USER_INFORMATION_URL, { headers }) |
206 | .map(res => Object.assign(obj, res)) | 205 | .pipe(map(res => Object.assign(obj, res))) |
207 | } | 206 | } |
208 | 207 | ||
209 | private handleLogin (obj: UserLoginWithUserInformation) { | 208 | private handleLogin (obj: UserLoginWithUserInformation) { |
diff --git a/client/src/app/core/confirm/confirm.service.ts b/client/src/app/core/confirm/confirm.service.ts index d99226f05..8419f622b 100644 --- a/client/src/app/core/confirm/confirm.service.ts +++ b/client/src/app/core/confirm/confirm.service.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import { first } from 'rxjs/operators' | ||
1 | import { Injectable } from '@angular/core' | 2 | import { Injectable } from '@angular/core' |
2 | import { Subject } from 'rxjs/Subject' | 3 | import { Subject } from 'rxjs' |
3 | import 'rxjs/add/operator/first' | ||
4 | import 'rxjs/add/operator/toPromise' | ||
5 | 4 | ||
6 | type ConfirmOptions = { | 5 | type ConfirmOptions = { |
7 | title: string | 6 | title: string |
@@ -19,12 +18,12 @@ export class ConfirmService { | |||
19 | confirm (message: string, title = '', confirmButtonText?: string) { | 18 | confirm (message: string, title = '', confirmButtonText?: string) { |
20 | this.showConfirm.next({ title, message, confirmButtonText }) | 19 | this.showConfirm.next({ title, message, confirmButtonText }) |
21 | 20 | ||
22 | return this.confirmResponse.asObservable().first().toPromise() | 21 | return this.confirmResponse.asObservable().pipe(first()).toPromise() |
23 | } | 22 | } |
24 | 23 | ||
25 | confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) { | 24 | confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) { |
26 | this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText }) | 25 | this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText }) |
27 | 26 | ||
28 | return this.confirmResponse.asObservable().first().toPromise() | 27 | return this.confirmResponse.asObservable().pipe(first()).toPromise() |
29 | } | 28 | } |
30 | } | 29 | } |
diff --git a/client/src/app/core/routing/preload-selected-modules-list.ts b/client/src/app/core/routing/preload-selected-modules-list.ts index 8a458ec3e..3bca60317 100644 --- a/client/src/app/core/routing/preload-selected-modules-list.ts +++ b/client/src/app/core/routing/preload-selected-modules-list.ts | |||
@@ -1,14 +1,13 @@ | |||
1 | import { Route, PreloadingStrategy } from '@angular/router' | 1 | import { Observable, timer as observableTimer, of as ofObservable } from 'rxjs' |
2 | import { Observable } from 'rxjs/Observable' | 2 | import { switchMap } from 'rxjs/operators' |
3 | import 'rxjs/add/observable/timer' | 3 | import { PreloadingStrategy, Route } from '@angular/router' |
4 | import 'rxjs/add/operator/switchMap' | ||
5 | 4 | ||
6 | export class PreloadSelectedModulesList implements PreloadingStrategy { | 5 | export class PreloadSelectedModulesList implements PreloadingStrategy { |
7 | preload (route: Route, load: Function): Observable<any> { | 6 | preload (route: Route, load: Function): Observable<any> { |
8 | if (!route.data || !route.data.preload) return Observable.of(null) | 7 | if (!route.data || !route.data.preload) return ofObservable(null) |
9 | 8 | ||
10 | if (typeof route.data.preload === 'number') { | 9 | if (typeof route.data.preload === 'number') { |
11 | return Observable.timer(route.data.preload).switchMap(() => load()) | 10 | return observableTimer(route.data.preload).pipe(switchMap(() => load())) |
12 | } | 11 | } |
13 | 12 | ||
14 | return load() | 13 | return load() |
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index a71c6d0bf..c5353023b 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import { tap } from 'rxjs/operators' | ||
1 | import { HttpClient } from '@angular/common/http' | 2 | import { HttpClient } from '@angular/common/http' |
2 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
3 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' | 4 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' |
4 | import 'rxjs/add/operator/do' | 5 | import { ReplaySubject } from 'rxjs' |
5 | import { ReplaySubject } from 'rxjs/ReplaySubject' | ||
6 | import { ServerConfig } from '../../../../../shared' | 6 | import { ServerConfig } from '../../../../../shared' |
7 | import { About } from '../../../../../shared/models/server/about.model' | 7 | import { About } from '../../../../../shared/models/server/about.model' |
8 | import { environment } from '../../../environments/environment' | 8 | import { environment } from '../../../environments/environment' |
@@ -69,12 +69,12 @@ export class ServerService { | |||
69 | 69 | ||
70 | loadConfig () { | 70 | loadConfig () { |
71 | this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL) | 71 | this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL) |
72 | .do(this.saveConfigLocally) | 72 | .pipe(tap(this.saveConfigLocally)) |
73 | .subscribe(data => { | 73 | .subscribe(data => { |
74 | this.config = data | 74 | this.config = data |
75 | 75 | ||
76 | this.configLoaded.next(true) | 76 | this.configLoaded.next(true) |
77 | }) | 77 | }) |
78 | } | 78 | } |
79 | 79 | ||
80 | loadVideoCategories () { | 80 | loadVideoCategories () { |