From db400f447a9f7aae1c56fa25396e93069744483f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 15 May 2018 11:55:51 +0200 Subject: Upgrade to rxjs 6 --- client/src/app/shared/video/video.service.ts | 89 +++++++++++++++++----------- 1 file changed, 55 insertions(+), 34 deletions(-) (limited to 'client/src/app/shared/video/video.service.ts') diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index cd8539b41..f57cb6d6d 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts @@ -1,8 +1,7 @@ +import { catchError, map } from 'rxjs/operators' import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' import { Injectable } from '@angular/core' -import 'rxjs/add/operator/catch' -import 'rxjs/add/operator/map' -import { Observable } from 'rxjs/Observable' +import { Observable } from 'rxjs' import { Video as VideoServerModel, VideoDetails as VideoDetailsServerModel } from '../../../../../shared' import { ResultList } from '../../../../../shared/models/result-list.model' import { UserVideoRateUpdate } from '../../../../../shared/models/videos/user-video-rate-update.model' @@ -43,14 +42,18 @@ export class VideoService { getVideo (uuid: string): Observable { return this.authHttp.get(VideoService.BASE_VIDEO_URL + uuid) - .map(videoHash => new VideoDetails(videoHash)) - .catch((res) => this.restExtractor.handleError(res)) + .pipe( + map(videoHash => new VideoDetails(videoHash)), + catchError(res => this.restExtractor.handleError(res)) + ) } viewVideo (uuid: string): Observable { return this.authHttp.post(this.getVideoViewUrl(uuid), {}) - .map(this.restExtractor.extractDataBool) - .catch(this.restExtractor.handleError) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(this.restExtractor.handleError) + ) } updateVideo (video: VideoEdit) { @@ -79,16 +82,18 @@ export class VideoService { const data = objectToFormData(body) return this.authHttp.put(VideoService.BASE_VIDEO_URL + video.id, data) - .map(this.restExtractor.extractDataBool) - .catch(this.restExtractor.handleError) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(this.restExtractor.handleError) + ) } uploadVideo (video: FormData) { const req = new HttpRequest('POST', VideoService.BASE_VIDEO_URL + 'upload', video, { reportProgress: true }) return this.authHttp - .request(req) - .catch(this.restExtractor.handleError) + .request(req) + .pipe(catchError(this.restExtractor.handleError)) } getMyVideos (videoPagination: ComponentPagination, sort: VideoSortField): Observable<{ videos: Video[], totalVideos: number}> { @@ -98,8 +103,10 @@ export class VideoService { params = this.restService.addRestGetParams(params, pagination, sort) return this.authHttp.get(UserService.BASE_USERS_URL + '/me/videos', { params }) - .map(this.extractVideos) - .catch((res) => this.restExtractor.handleError(res)) + .pipe( + map(this.extractVideos), + catchError(res => this.restExtractor.handleError(res)) + ) } getAccountVideos ( @@ -114,8 +121,10 @@ export class VideoService { return this.authHttp .get(AccountService.BASE_ACCOUNT_URL + account.id + '/videos', { params }) - .map(this.extractVideos) - .catch((res) => this.restExtractor.handleError(res)) + .pipe( + map(this.extractVideos), + catchError(res => this.restExtractor.handleError(res)) + ) } getVideoChannelVideos ( @@ -130,8 +139,10 @@ export class VideoService { return this.authHttp .get(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.uuid + '/videos', { params }) - .map(this.extractVideos) - .catch((res) => this.restExtractor.handleError(res)) + .pipe( + map(this.extractVideos), + catchError(res => this.restExtractor.handleError(res)) + ) } getVideos ( @@ -149,9 +160,11 @@ export class VideoService { } return this.authHttp - .get(VideoService.BASE_VIDEO_URL, { params }) - .map(this.extractVideos) - .catch((res) => this.restExtractor.handleError(res)) + .get(VideoService.BASE_VIDEO_URL, { params }) + .pipe( + map(this.extractVideos), + catchError(res => this.restExtractor.handleError(res)) + ) } buildBaseFeedUrls (params: HttpParams) { @@ -215,23 +228,29 @@ export class VideoService { params = params.append('search', search) return this.authHttp - .get>(url, { params }) - .map(this.extractVideos) - .catch((res) => this.restExtractor.handleError(res)) + .get>(url, { params }) + .pipe( + map(this.extractVideos), + catchError(res => this.restExtractor.handleError(res)) + ) } removeVideo (id: number) { return this.authHttp - .delete(VideoService.BASE_VIDEO_URL + id) - .map(this.restExtractor.extractDataBool) - .catch((res) => this.restExtractor.handleError(res)) + .delete(VideoService.BASE_VIDEO_URL + id) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(res => this.restExtractor.handleError(res)) + ) } loadCompleteDescription (descriptionPath: string) { return this.authHttp - .get(environment.apiUrl + descriptionPath) - .map(res => res['description']) - .catch((res) => this.restExtractor.handleError(res)) + .get(environment.apiUrl + descriptionPath) + .pipe( + map(res => res[ 'description' ]), + catchError(res => this.restExtractor.handleError(res)) + ) } setVideoLike (id: number) { @@ -250,8 +269,8 @@ export class VideoService { const url = UserService.BASE_USERS_URL + 'me/videos/' + id + '/rating' return this.authHttp - .get(url) - .catch(res => this.restExtractor.handleError(res)) + .get(url) + .pipe(catchError(res => this.restExtractor.handleError(res))) } private setVideoRate (id: number, rateType: VideoRateType) { @@ -261,9 +280,11 @@ export class VideoService { } return this.authHttp - .put(url, body) - .map(this.restExtractor.extractDataBool) - .catch(res => this.restExtractor.handleError(res)) + .put(url, body) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(res => this.restExtractor.handleError(res)) + ) } private extractVideos (result: ResultList) { -- cgit v1.2.3