]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video-channel/video-channel.service.ts
Try to fix bcrypt on node 8.12
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-channel / video-channel.service.ts
CommitLineData
db400f44 1import { catchError, map, tap } from 'rxjs/operators'
d3e91a5f 2import { Injectable } from '@angular/core'
db400f44 3import { Observable, ReplaySubject } from 'rxjs'
d3e91a5f 4import { RestExtractor } from '../rest/rest-extractor.service'
d3e91a5f 5import { HttpClient } from '@angular/common/http'
08c1efbe 6import { VideoChannel as VideoChannelServer, VideoChannelCreate, VideoChannelUpdate } from '../../../../../shared/models/videos'
d3e91a5f
C
7import { AccountService } from '../account/account.service'
8import { ResultList } from '../../../../../shared'
9import { VideoChannel } from './video-channel.model'
170726f5 10import { environment } from '../../../environments/environment'
ad9e39fb 11import { Account } from '@app/shared/account/account.model'
52d9f792 12import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
d3e91a5f
C
13
14@Injectable()
15export class VideoChannelService {
170726f5
C
16 static BASE_VIDEO_CHANNEL_URL = environment.apiUrl + '/api/v1/video-channels/'
17
18 videoChannelLoaded = new ReplaySubject<VideoChannel>(1)
19
22a16e36
C
20 static extractVideoChannels (result: ResultList<VideoChannelServer>) {
21 const videoChannels: VideoChannel[] = []
22
23 for (const videoChannelJSON of result.data) {
24 videoChannels.push(new VideoChannel(videoChannelJSON))
25 }
26
27 return { data: videoChannels, total: result.total }
28 }
29
f6eebcb3
C
30 constructor (
31 private authHttp: HttpClient,
32 private restExtractor: RestExtractor
33 ) { }
34
8a19bee1
C
35 getVideoChannel (videoChannelName: string) {
36 return this.authHttp.get<VideoChannel>(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName)
db400f44
C
37 .pipe(
38 map(videoChannelHash => new VideoChannel(videoChannelHash)),
39 tap(videoChannel => this.videoChannelLoaded.next(videoChannel)),
e4f0e92e 40 catchError(err => this.restExtractor.handleError(err))
db400f44 41 )
170726f5
C
42 }
43
ad9e39fb
C
44 listAccountVideoChannels (account: Account): Observable<ResultList<VideoChannel>> {
45 return this.authHttp.get<ResultList<VideoChannelServer>>(AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/video-channels')
db400f44 46 .pipe(
22a16e36 47 map(res => VideoChannelService.extractVideoChannels(res)),
e4f0e92e 48 catchError(err => this.restExtractor.handleError(err))
db400f44 49 )
d3e91a5f
C
50 }
51
08c1efbe
C
52 createVideoChannel (videoChannel: VideoChannelCreate) {
53 return this.authHttp.post(VideoChannelService.BASE_VIDEO_CHANNEL_URL, videoChannel)
db400f44
C
54 .pipe(
55 map(this.restExtractor.extractDataBool),
56 catchError(err => this.restExtractor.handleError(err))
57 )
08c1efbe
C
58 }
59
22a16e36
C
60 updateVideoChannel (videoChannelName: string, videoChannel: VideoChannelUpdate) {
61 return this.authHttp.put(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName, videoChannel)
db400f44
C
62 .pipe(
63 map(this.restExtractor.extractDataBool),
64 catchError(err => this.restExtractor.handleError(err))
65 )
08c1efbe
C
66 }
67
22a16e36
C
68 changeVideoChannelAvatar (videoChannelName: string, avatarForm: FormData) {
69 const url = VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannelName + '/avatar/pick'
52d9f792
C
70
71 return this.authHttp.post<{ avatar: Avatar }>(url, avatarForm)
e4f0e92e 72 .pipe(catchError(err => this.restExtractor.handleError(err)))
52d9f792
C
73 }
74
08c1efbe
C
75 removeVideoChannel (videoChannel: VideoChannel) {
76 return this.authHttp.delete(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.uuid)
db400f44
C
77 .pipe(
78 map(this.restExtractor.extractDataBool),
79 catchError(err => this.restExtractor.handleError(err))
80 )
08c1efbe 81 }
d3e91a5f 82}