]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video-abuse/video-abuse.service.ts
Add bulk comment actions on account dropdown
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-abuse / video-abuse.service.ts
CommitLineData
db400f44 1import { catchError, map } from 'rxjs/operators'
d592e0a9 2import { HttpClient, HttpParams } from '@angular/common/http'
63c4db6d 3import { Injectable } from '@angular/core'
f77eb73b 4import { SortMeta } from 'primeng/api'
db400f44 5import { Observable } from 'rxjs'
feb34f6b 6import { ResultList, VideoAbuse, VideoAbuseUpdate, VideoAbuseState } from '../../../../../shared'
63c4db6d 7import { environment } from '../../../environments/environment'
61bbc727 8import { RestExtractor, RestPagination, RestService } from '../rest'
11ac88de
C
9
10@Injectable()
11export class VideoAbuseService {
63c4db6d 12 private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/'
11ac88de 13
df98563e 14 constructor (
d592e0a9
C
15 private authHttp: HttpClient,
16 private restService: RestService,
11ac88de
C
17 private restExtractor: RestExtractor
18 ) {}
19
844db39e
RK
20 getVideoAbuses (options: {
21 pagination: RestPagination,
22 sort: SortMeta,
23 search?: string
24 }): Observable<ResultList<VideoAbuse>> {
25 const { pagination, sort, search } = options
d592e0a9
C
26 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
27
28 let params = new HttpParams()
29 params = this.restService.addRestGetParams(params, pagination, sort)
30
feb34f6b
C
31 if (search) {
32 const filters = this.restService.parseQueryStringFilter(search, {
33 id: { prefix: '#' },
34 state: {
35 prefix: 'state:',
36 handler: v => {
37 if (v === 'accepted') return VideoAbuseState.ACCEPTED
38 if (v === 'pending') return VideoAbuseState.PENDING
39 if (v === 'rejected') return VideoAbuseState.REJECTED
40
41 return undefined
42 }
43 },
44 videoIs: {
45 prefix: 'videoIs:',
46 handler: v => {
47 if (v === 'deleted') return v
48 if (v === 'blacklisted') return v
49
50 return undefined
51 }
52 },
53 searchReporter: { prefix: 'reporter:' },
54 searchReportee: { prefix: 'reportee:' }
55 })
56
57 params = this.restService.addObjectParams(params, filters)
58 }
844db39e 59
d592e0a9 60 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
db400f44 61 .pipe(
db400f44
C
62 catchError(res => this.restExtractor.handleError(res))
63 )
11ac88de
C
64 }
65
0a6658fd 66 reportVideo (id: number, reason: string) {
d592e0a9 67 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
1506307f 68 const body = { reason }
11ac88de
C
69
70 return this.authHttp.post(url, body)
db400f44
C
71 .pipe(
72 map(this.restExtractor.extractDataBool),
73 catchError(res => this.restExtractor.handleError(res))
74 )
11ac88de 75 }
efc9e845
C
76
77 updateVideoAbuse (videoAbuse: VideoAbuse, abuseUpdate: VideoAbuseUpdate) {
78 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
79
80 return this.authHttp.put(url, abuseUpdate)
81 .pipe(
82 map(this.restExtractor.extractDataBool),
83 catchError(res => this.restExtractor.handleError(res))
84 )
85 }
86
87 removeVideoAbuse (videoAbuse: VideoAbuse) {
88 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
89
90 return this.authHttp.delete(url)
91 .pipe(
92 map(this.restExtractor.extractDataBool),
93 catchError(res => this.restExtractor.handleError(res))
94 )
95 }}