]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video-channel/video-channel.service.ts
Implement video channel views
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-channel / video-channel.service.ts
CommitLineData
d3e91a5f
C
1import { Injectable } from '@angular/core'
2import 'rxjs/add/operator/catch'
3import 'rxjs/add/operator/map'
4import { Observable } from 'rxjs/Observable'
5import { RestExtractor } from '../rest/rest-extractor.service'
6import { RestService } from '../rest/rest.service'
7import { HttpClient } from '@angular/common/http'
8import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos'
9import { AccountService } from '../account/account.service'
10import { ResultList } from '../../../../../shared'
11import { VideoChannel } from './video-channel.model'
170726f5
C
12import { ReplaySubject } from 'rxjs/ReplaySubject'
13import { environment } from '../../../environments/environment'
d3e91a5f
C
14
15@Injectable()
16export class VideoChannelService {
170726f5
C
17 static BASE_VIDEO_CHANNEL_URL = environment.apiUrl + '/api/v1/video-channels/'
18
19 videoChannelLoaded = new ReplaySubject<VideoChannel>(1)
20
d3e91a5f
C
21 constructor (
22 private authHttp: HttpClient,
23 private restExtractor: RestExtractor,
24 private restService: RestService
25 ) {}
26
170726f5
C
27 getVideoChannel (videoChannelUUID: string) {
28 return this.authHttp.get<VideoChannel>(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelUUID)
29 .map(videoChannelHash => new VideoChannel(videoChannelHash))
30 .do(videoChannel => this.videoChannelLoaded.next(videoChannel))
31 .catch((res) => this.restExtractor.handleError(res))
32 }
33
34 listAccountVideoChannels (accountId: number): Observable<ResultList<VideoChannel>> {
d3e91a5f
C
35 return this.authHttp.get<ResultList<VideoChannelServer>>(AccountService.BASE_ACCOUNT_URL + accountId + '/video-channels')
36 .map(res => this.extractVideoChannels(res))
37 .catch((res) => this.restExtractor.handleError(res))
38 }
39
40 private extractVideoChannels (result: ResultList<VideoChannelServer>) {
41 const videoChannels: VideoChannel[] = []
42
43 for (const videoChannelJSON of result.data) {
44 videoChannels.push(new VideoChannel(videoChannelJSON))
45 }
46
47 return { data: videoChannels, total: result.total }
48 }
49}