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