]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/video-abuse/video-abuse.service.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-abuse / video-abuse.service.ts
1 import { catchError, map } from 'rxjs/operators'
2 import { HttpClient, HttpParams } from '@angular/common/http'
3 import { Injectable } from '@angular/core'
4 import { SortMeta } from 'primeng/api'
5 import { Observable } from 'rxjs'
6 import { ResultList, VideoAbuse, VideoAbuseUpdate } from '../../../../../shared'
7 import { environment } from '../../../environments/environment'
8 import { RestExtractor, RestPagination, RestService } from '../rest'
9
10 @Injectable()
11 export class VideoAbuseService {
12 private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/'
13
14 constructor (
15 private authHttp: HttpClient,
16 private restService: RestService,
17 private restExtractor: RestExtractor
18 ) {}
19
20 getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> {
21 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
22
23 let params = new HttpParams()
24 params = this.restService.addRestGetParams(params, pagination, sort)
25
26 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
27 .pipe(
28 map(res => this.restExtractor.convertResultListDateToHuman(res)),
29 catchError(res => this.restExtractor.handleError(res))
30 )
31 }
32
33 reportVideo (id: number, reason: string) {
34 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
35 const body = { reason }
36
37 return this.authHttp.post(url, body)
38 .pipe(
39 map(this.restExtractor.extractDataBool),
40 catchError(res => this.restExtractor.handleError(res))
41 )
42 }
43
44 updateVideoAbuse (videoAbuse: VideoAbuse, abuseUpdate: VideoAbuseUpdate) {
45 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
46
47 return this.authHttp.put(url, abuseUpdate)
48 .pipe(
49 map(this.restExtractor.extractDataBool),
50 catchError(res => this.restExtractor.handleError(res))
51 )
52 }
53
54 removeVideoAbuse (videoAbuse: VideoAbuse) {
55 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
56
57 return this.authHttp.delete(url)
58 .pipe(
59 map(this.restExtractor.extractDataBool),
60 catchError(res => this.restExtractor.handleError(res))
61 )
62 }}