aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video-block/video-block.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/video-block/video-block.service.ts')
-rw-r--r--client/src/app/shared/video-block/video-block.service.ts77
1 files changed, 77 insertions, 0 deletions
diff --git a/client/src/app/shared/video-block/video-block.service.ts b/client/src/app/shared/video-block/video-block.service.ts
new file mode 100644
index 000000000..67ca1d85b
--- /dev/null
+++ b/client/src/app/shared/video-block/video-block.service.ts
@@ -0,0 +1,77 @@
1import { catchError, map, concatMap, toArray } from 'rxjs/operators'
2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core'
4import { SortMeta } from 'primeng/api'
5import { from as observableFrom, Observable } from 'rxjs'
6import { VideoBlocklist, VideoBlockType, ResultList } from '../../../../../shared'
7import { environment } from '../../../environments/environment'
8import { RestExtractor, RestPagination, RestService } from '../rest'
9
10@Injectable()
11export class VideoBlockService {
12 private static BASE_VIDEOS_URL = environment.apiUrl + '/api/v1/videos/'
13
14 constructor (
15 private authHttp: HttpClient,
16 private restService: RestService,
17 private restExtractor: RestExtractor
18 ) {}
19
20 listBlocks (options: {
21 pagination: RestPagination
22 sort: SortMeta
23 search?: string
24 type?: VideoBlockType
25 }): Observable<ResultList<VideoBlocklist>> {
26 const { pagination, sort, search, type } = options
27
28 let params = new HttpParams()
29 params = this.restService.addRestGetParams(params, pagination, sort)
30
31 if (search) {
32 const filters = this.restService.parseQueryStringFilter(search, {
33 type: {
34 prefix: 'type:',
35 handler: v => {
36 if (v === 'manual') return VideoBlockType.MANUAL
37 if (v === 'auto') return VideoBlockType.AUTO_BEFORE_PUBLISHED
38
39 return undefined
40 }
41 }
42 })
43
44 params = this.restService.addObjectParams(params, filters)
45 }
46
47 return this.authHttp.get<ResultList<VideoBlocklist>>(VideoBlockService.BASE_VIDEOS_URL + 'blacklist', { params })
48 .pipe(
49 map(res => this.restExtractor.convertResultListDateToHuman(res)),
50 catchError(res => this.restExtractor.handleError(res))
51 )
52 }
53
54 unblockVideo (videoIdArgs: number | number[]) {
55 const videoIds = Array.isArray(videoIdArgs) ? videoIdArgs : [ videoIdArgs ]
56
57 return observableFrom(videoIds)
58 .pipe(
59 concatMap(id => this.authHttp.delete(VideoBlockService.BASE_VIDEOS_URL + id + '/blacklist')),
60 toArray(),
61 catchError(err => this.restExtractor.handleError(err))
62 )
63 }
64
65 blockVideo (videoId: number, reason: string, unfederate: boolean) {
66 const body = {
67 unfederate,
68 reason
69 }
70
71 return this.authHttp.post(VideoBlockService.BASE_VIDEOS_URL + videoId + '/blacklist', body)
72 .pipe(
73 map(this.restExtractor.extractDataBool),
74 catchError(res => this.restExtractor.handleError(res))
75 )
76 }
77}