aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video/video.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/video/video.service.ts')
-rw-r--r--client/src/app/shared/video/video.service.ts56
1 files changed, 34 insertions, 22 deletions
diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts
index d1e32faeb..c607b7d6a 100644
--- a/client/src/app/shared/video/video.service.ts
+++ b/client/src/app/shared/video/video.service.ts
@@ -1,4 +1,4 @@
1import { catchError, map } from 'rxjs/operators' 1import { catchError, map, switchMap } from 'rxjs/operators'
2import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' 2import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http'
3import { Injectable } from '@angular/core' 3import { Injectable } from '@angular/core'
4import { Observable } from 'rxjs' 4import { Observable } from 'rxjs'
@@ -24,6 +24,7 @@ import { Account } from '@app/shared/account/account.model'
24import { AccountService } from '@app/shared/account/account.service' 24import { AccountService } from '@app/shared/account/account.service'
25import { VideoChannel } from '../../../../../shared/models/videos' 25import { VideoChannel } from '../../../../../shared/models/videos'
26import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' 26import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
27import { ServerService } from '@app/core'
27 28
28@Injectable() 29@Injectable()
29export class VideoService { 30export class VideoService {
@@ -33,7 +34,8 @@ export class VideoService {
33 constructor ( 34 constructor (
34 private authHttp: HttpClient, 35 private authHttp: HttpClient,
35 private restExtractor: RestExtractor, 36 private restExtractor: RestExtractor,
36 private restService: RestService 37 private restService: RestService,
38 private serverService: ServerService
37 ) {} 39 ) {}
38 40
39 getVideoViewUrl (uuid: string) { 41 getVideoViewUrl (uuid: string) {
@@ -41,9 +43,13 @@ export class VideoService {
41 } 43 }
42 44
43 getVideo (uuid: string): Observable<VideoDetails> { 45 getVideo (uuid: string): Observable<VideoDetails> {
44 return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid) 46 return this.serverService.localeObservable
45 .pipe( 47 .pipe(
46 map(videoHash => new VideoDetails(videoHash)), 48 switchMap(translations => {
49 return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid)
50 .pipe(map(videoHash => ({ videoHash, translations })))
51 }),
52 map(({ videoHash, translations }) => new VideoDetails(videoHash, translations)),
47 catchError(res => this.restExtractor.handleError(res)) 53 catchError(res => this.restExtractor.handleError(res))
48 ) 54 )
49 } 55 }
@@ -102,9 +108,10 @@ export class VideoService {
102 let params = new HttpParams() 108 let params = new HttpParams()
103 params = this.restService.addRestGetParams(params, pagination, sort) 109 params = this.restService.addRestGetParams(params, pagination, sort)
104 110
105 return this.authHttp.get(UserService.BASE_USERS_URL + '/me/videos', { params }) 111 return this.authHttp
112 .get<ResultList<Video>>(UserService.BASE_USERS_URL + '/me/videos', { params })
106 .pipe( 113 .pipe(
107 map(this.extractVideos), 114 switchMap(res => this.extractVideos(res)),
108 catchError(res => this.restExtractor.handleError(res)) 115 catchError(res => this.restExtractor.handleError(res))
109 ) 116 )
110 } 117 }
@@ -120,9 +127,9 @@ export class VideoService {
120 params = this.restService.addRestGetParams(params, pagination, sort) 127 params = this.restService.addRestGetParams(params, pagination, sort)
121 128
122 return this.authHttp 129 return this.authHttp
123 .get(AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/videos', { params }) 130 .get<ResultList<Video>>(AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/videos', { params })
124 .pipe( 131 .pipe(
125 map(this.extractVideos), 132 switchMap(res => this.extractVideos(res)),
126 catchError(res => this.restExtractor.handleError(res)) 133 catchError(res => this.restExtractor.handleError(res))
127 ) 134 )
128 } 135 }
@@ -138,9 +145,9 @@ export class VideoService {
138 params = this.restService.addRestGetParams(params, pagination, sort) 145 params = this.restService.addRestGetParams(params, pagination, sort)
139 146
140 return this.authHttp 147 return this.authHttp
141 .get(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.uuid + '/videos', { params }) 148 .get<ResultList<Video>>(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.uuid + '/videos', { params })
142 .pipe( 149 .pipe(
143 map(this.extractVideos), 150 switchMap(res => this.extractVideos(res)),
144 catchError(res => this.restExtractor.handleError(res)) 151 catchError(res => this.restExtractor.handleError(res))
145 ) 152 )
146 } 153 }
@@ -160,9 +167,9 @@ export class VideoService {
160 } 167 }
161 168
162 return this.authHttp 169 return this.authHttp
163 .get(VideoService.BASE_VIDEO_URL, { params }) 170 .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
164 .pipe( 171 .pipe(
165 map(this.extractVideos), 172 switchMap(res => this.extractVideos(res)),
166 catchError(res => this.restExtractor.handleError(res)) 173 catchError(res => this.restExtractor.handleError(res))
167 ) 174 )
168 } 175 }
@@ -230,7 +237,7 @@ export class VideoService {
230 return this.authHttp 237 return this.authHttp
231 .get<ResultList<VideoServerModel>>(url, { params }) 238 .get<ResultList<VideoServerModel>>(url, { params })
232 .pipe( 239 .pipe(
233 map(this.extractVideos), 240 switchMap(res => this.extractVideos(res)),
234 catchError(res => this.restExtractor.handleError(res)) 241 catchError(res => this.restExtractor.handleError(res))
235 ) 242 )
236 } 243 }
@@ -287,14 +294,19 @@ export class VideoService {
287 } 294 }
288 295
289 private extractVideos (result: ResultList<VideoServerModel>) { 296 private extractVideos (result: ResultList<VideoServerModel>) {
290 const videosJson = result.data 297 return this.serverService.localeObservable
291 const totalVideos = result.total 298 .pipe(
292 const videos = [] 299 map(translations => {
293 300 const videosJson = result.data
294 for (const videoJson of videosJson) { 301 const totalVideos = result.total
295 videos.push(new Video(videoJson)) 302 const videos: Video[] = []
296 } 303
297 304 for (const videoJson of videosJson) {
298 return { videos, totalVideos } 305 videos.push(new Video(videoJson, translations))
306 }
307
308 return { videos, totalVideos }
309 })
310 )
299 } 311 }
300} 312}