]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/shared/video-abuse/video-abuse.service.ts
Add ability to update a video channel
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-abuse / video-abuse.service.ts
... / ...
CommitLineData
1import { HttpClient, HttpParams } from '@angular/common/http'
2import { Injectable } from '@angular/core'
3import { SortMeta } from 'primeng/components/common/sortmeta'
4import 'rxjs/add/operator/catch'
5import 'rxjs/add/operator/map'
6import { Observable } from 'rxjs/Observable'
7import { ResultList, VideoAbuse } from '../../../../../shared'
8import { environment } from '../../../environments/environment'
9import { RestExtractor, RestPagination, RestService } from '../rest'
10
11@Injectable()
12export class VideoAbuseService {
13 private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/'
14
15 constructor (
16 private authHttp: HttpClient,
17 private restService: RestService,
18 private restExtractor: RestExtractor
19 ) {}
20
21 getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> {
22 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
23
24 let params = new HttpParams()
25 params = this.restService.addRestGetParams(params, pagination, sort)
26
27 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
28 .map(res => this.restExtractor.convertResultListDateToHuman(res))
29 .catch(res => this.restExtractor.handleError(res))
30 }
31
32 reportVideo (id: number, reason: string) {
33 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
34 const body = {
35 reason
36 }
37
38 return this.authHttp.post(url, body)
39 .map(this.restExtractor.extractDataBool)
40 .catch(res => this.restExtractor.handleError(res))
41 }
42}