From 1378c0d343028f3d40d7d795422684ab9e6a1599 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 17 Aug 2021 11:27:47 +0200 Subject: Fix client lint --- client/src/app/core/auth/auth.service.ts | 40 +++++++++++----------- client/src/app/core/confirm/confirm.service.ts | 11 ++---- client/src/app/core/plugins/plugin.service.ts | 17 +++++---- client/src/app/core/rest/rest-extractor.service.ts | 4 +-- 4 files changed, 35 insertions(+), 37 deletions(-) (limited to 'client/src/app/core') diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index ef5a3808e..5da66c981 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -80,8 +80,8 @@ export class AuthService { // Fetch the client_id/client_secret this.http.get(AuthService.BASE_CLIENT_URL) .pipe(catchError(res => this.restExtractor.handleError(res))) - .subscribe( - res => { + .subscribe({ + next: res => { this.clientId = res.client_id this.clientSecret = res.client_secret @@ -91,18 +91,18 @@ export class AuthService { console.log('Client credentials loaded.') }, - error => { - let errorMessage = error.message + error: err => { + let errorMessage = err.message - if (error.status === HttpStatusCode.FORBIDDEN_403) { - errorMessage = $localize`Cannot retrieve OAuth Client credentials: ${error.text}. + if (err.status === HttpStatusCode.FORBIDDEN_403) { + errorMessage = $localize`Cannot retrieve OAuth Client credentials: ${err.text}. Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.` } // We put a bigger timeout: this is an important message this.notifier.error(errorMessage, $localize`Error`, 7000) } - ) + }) } getRefreshToken () { @@ -168,15 +168,15 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular const headers = new HttpHeaders().set('Authorization', authHeaderValue) this.http.post<{ redirectUrl?: string }>(AuthService.BASE_REVOKE_TOKEN_URL, {}, { headers }) - .subscribe( - res => { - if (res.redirectUrl) { - window.location.href = res.redirectUrl - } - }, + .subscribe({ + next: res => { + if (res.redirectUrl) { + window.location.href = res.redirectUrl + } + }, - err => console.error(err) - ) + error: err => console.error(err) + }) this.user = null @@ -215,9 +215,9 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular this.logout() this.router.navigate([ '/login' ]) - return observableThrowError({ + return observableThrowError(() => ({ error: $localize`You need to reconnect.` - }) + })) }), share() ) @@ -234,14 +234,14 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular } this.mergeUserInformation(obj) - .subscribe( - res => { + .subscribe({ + next: res => { this.user.patch(res) this.user.save() this.userInformationLoaded.next(true) } - ) + }) } private mergeUserInformation (obj: UserLoginWithUsername): Observable { diff --git a/client/src/app/core/confirm/confirm.service.ts b/client/src/app/core/confirm/confirm.service.ts index 6e042c16b..338b8762c 100644 --- a/client/src/app/core/confirm/confirm.service.ts +++ b/client/src/app/core/confirm/confirm.service.ts @@ -1,6 +1,5 @@ -import { first } from 'rxjs/operators' +import { firstValueFrom, Subject } from 'rxjs' import { Injectable } from '@angular/core' -import { Subject } from 'rxjs' type ConfirmOptions = { title: string @@ -18,16 +17,12 @@ export class ConfirmService { confirm (message: string, title = '', confirmButtonText?: string) { this.showConfirm.next({ title, message, confirmButtonText }) - return this.confirmResponse.asObservable() - .pipe(first()) - .toPromise() + return firstValueFrom(this.confirmResponse.asObservable()) } confirmWithInput (message: string, inputLabel: string, expectedInputValue: string, title = '', confirmButtonText?: string) { this.showConfirm.next({ title, message, inputLabel, expectedInputValue, confirmButtonText }) - return this.confirmResponse.asObservable() - .pipe(first()) - .toPromise() + return firstValueFrom(this.confirmResponse.asObservable()) } } diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index 16108e17a..774c03964 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts @@ -1,4 +1,4 @@ -import { Observable, of } from 'rxjs' +import { firstValueFrom, Observable, of } from 'rxjs' import { catchError, map, shareReplay } from 'rxjs/operators' import { HttpClient } from '@angular/common/http' import { Inject, Injectable, LOCALE_ID, NgZone } from '@angular/core' @@ -164,18 +164,20 @@ export class PluginService implements ClientHook { getSettings: () => { const path = PluginService.BASE_PLUGIN_API_URL + '/' + npmName + '/public-settings' - return this.authHttp.get(path) + const obs = this.authHttp.get(path) .pipe( map(p => p.publicSettings), catchError(res => this.restExtractor.handleError(res)) ) - .toPromise() + + return firstValueFrom(obs) }, getServerConfig: () => { - return this.server.getConfig() + const obs = this.server.getConfig() .pipe(catchError(res => this.restExtractor.handleError(res))) - .toPromise() + + return firstValueFrom(obs) }, isLoggedIn: () => { @@ -216,10 +218,11 @@ export class PluginService implements ClientHook { }, translate: (value: string) => { - return this.translationsObservable + const obs = this.translationsObservable .pipe(map(allTranslations => allTranslations[npmName])) .pipe(map(translations => peertubeTranslate(value, translations))) - .toPromise() + + return firstValueFrom(obs) } } } diff --git a/client/src/app/core/rest/rest-extractor.service.ts b/client/src/app/core/rest/rest-extractor.service.ts index 2a926e68f..29a56ba39 100644 --- a/client/src/app/core/rest/rest-extractor.service.ts +++ b/client/src/app/core/rest/rest-extractor.service.ts @@ -89,7 +89,7 @@ export class RestExtractor { errorObj.body = err.error } - return observableThrowError(errorObj) + return observableThrowError(() => errorObj) } redirectTo404IfNotFound (obj: { status: number }, type: 'video' | 'other', status = [ HttpStatusCode.NOT_FOUND_404 ]) { @@ -98,6 +98,6 @@ export class RestExtractor { this.router.navigate([ '/404' ], { state: { type, obj }, skipLocationChange: true }) } - return observableThrowError(obj) + return observableThrowError(() => obj) } } -- cgit v1.2.3