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