PeerTube/client/src/app/shared/video-abuse/video-abuse.service.ts

63 lines
2.3 KiB
TypeScript
Raw Normal View History

2018-05-15 04:55:51 -05:00
import { catchError, map } from 'rxjs/operators'
import { HttpClient, HttpParams } from '@angular/common/http'
2017-12-11 10:36:46 -06:00
import { Injectable } from '@angular/core'
2020-02-07 03:27:16 -06:00
import { SortMeta } from 'primeng/api'
2018-05-15 04:55:51 -05:00
import { Observable } from 'rxjs'
import { ResultList, VideoAbuse, VideoAbuseUpdate } from '../../../../../shared'
2017-12-11 10:36:46 -06:00
import { environment } from '../../../environments/environment'
2018-01-31 03:41:44 -06:00
import { RestExtractor, RestPagination, RestService } from '../rest'
@Injectable()
export class VideoAbuseService {
2017-12-11 10:36:46 -06:00
private static BASE_VIDEO_ABUSE_URL = environment.apiUrl + '/api/v1/videos/'
constructor (
private authHttp: HttpClient,
private restService: RestService,
private restExtractor: RestExtractor
) {}
getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> {
const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
let params = new HttpParams()
params = this.restService.addRestGetParams(params, pagination, sort)
return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
2018-05-15 04:55:51 -05:00
.pipe(
map(res => this.restExtractor.convertResultListDateToHuman(res)),
catchError(res => this.restExtractor.handleError(res))
)
}
reportVideo (id: number, reason: string) {
const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
const body = { reason }
return this.authHttp.post(url, body)
2018-05-15 04:55:51 -05:00
.pipe(
map(this.restExtractor.extractDataBool),
catchError(res => this.restExtractor.handleError(res))
)
}
updateVideoAbuse (videoAbuse: VideoAbuse, abuseUpdate: VideoAbuseUpdate) {
const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
return this.authHttp.put(url, abuseUpdate)
.pipe(
map(this.restExtractor.extractDataBool),
catchError(res => this.restExtractor.handleError(res))
)
}
removeVideoAbuse (videoAbuse: VideoAbuse) {
const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + videoAbuse.video.uuid + '/abuse/' + videoAbuse.id
return this.authHttp.delete(url)
.pipe(
map(this.restExtractor.extractDataBool),
catchError(res => this.restExtractor.handleError(res))
)
}}