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