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