]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video-blacklist/video-blacklist.service.ts
Fix client search
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-blacklist / video-blacklist.service.ts
CommitLineData
792dbaf0
GS
1import { Injectable } from '@angular/core'
2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Observable } from 'rxjs/Observable'
4import 'rxjs/add/operator/catch'
5import 'rxjs/add/operator/map'
6
7import { SortMeta } from 'primeng/components/common/sortmeta'
8
35bf0c83
C
9import { RestExtractor, RestPagination, RestService } from '../rest'
10import { Utils } from '../utils'
11import { BlacklistedVideo, ResultList } from '../../../../../shared'
792dbaf0
GS
12
13@Injectable()
35bf0c83
C
14export class VideoBlacklistService {
15 private static BASE_VIDEOS_URL = API_URL + '/api/v1/videos/'
792dbaf0
GS
16
17 constructor (
18 private authHttp: HttpClient,
19 private restService: RestService,
20 private restExtractor: RestExtractor
21 ) {}
22
35bf0c83 23 listBlacklist (pagination: RestPagination, sort: SortMeta): Observable<ResultList<BlacklistedVideo>> {
792dbaf0
GS
24 let params = new HttpParams()
25 params = this.restService.addRestGetParams(params, pagination, sort)
26
35bf0c83 27 return this.authHttp.get<ResultList<BlacklistedVideo>>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params })
792dbaf0
GS
28 .map(res => this.restExtractor.convertResultListDateToHuman(res))
29 .map(res => this.restExtractor.applyToResultListData(res, this.formatBlacklistedVideo.bind(this)))
30 .catch(res => this.restExtractor.handleError(res))
31 }
32
35bf0c83
C
33 removeVideoFromBlacklist (videoId: number) {
34 return this.authHttp.delete(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist')
792dbaf0
GS
35 .map(this.restExtractor.extractDataBool)
36 .catch(res => this.restExtractor.handleError(res))
37 }
38
35bf0c83
C
39 blacklistVideo (videoId: number) {
40 return this.authHttp.post(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist', {})
41 .map(this.restExtractor.extractDataBool)
42 .catch(res => this.restExtractor.handleError(res))
43 }
44
792dbaf0
GS
45 private formatBlacklistedVideo (blacklistedVideo: BlacklistedVideo) {
46 return Object.assign(blacklistedVideo, {
47 createdAt: Utils.dateToHuman(blacklistedVideo.createdAt)
48 })
49 }
50}