aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video-block
diff options
context:
space:
mode:
authorChocobozzz <chocobozzz@framasoft.org>2020-06-11 10:36:04 +0200
committerChocobozzz <chocobozzz@framasoft.org>2020-06-11 10:36:04 +0200
commitfa58a19819cb821a5c5a26802efd492461be9c04 (patch)
tree72bd8307da8ac447bb9934b1301ab0d93ea97e6b /client/src/app/shared/video-block
parent50a04125dac1a126cb79a9fb575fcf673c5ac2d6 (diff)
parente95bede8fe660a38c99e51560caa5dd58a8eb23e (diff)
downloadPeerTube-fa58a19819cb821a5c5a26802efd492461be9c04.tar.gz
PeerTube-fa58a19819cb821a5c5a26802efd492461be9c04.tar.zst
PeerTube-fa58a19819cb821a5c5a26802efd492461be9c04.zip
Merge branch 'blacklist' into 'develop'
rename blacklist to block/blocklist, merge block and auto-block views See merge request framasoft/peertube/PeerTube!30
Diffstat (limited to 'client/src/app/shared/video-block')
-rw-r--r--client/src/app/shared/video-block/index.ts1
-rw-r--r--client/src/app/shared/video-block/video-block.service.ts78
2 files changed, 79 insertions, 0 deletions
diff --git a/client/src/app/shared/video-block/index.ts b/client/src/app/shared/video-block/index.ts
new file mode 100644
index 000000000..a99551a38
--- /dev/null
+++ b/client/src/app/shared/video-block/index.ts
@@ -0,0 +1 @@
export * from './video-block.service'
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..d0673ddba
--- /dev/null
+++ b/client/src/app/shared/video-block/video-block.service.ts
@@ -0,0 +1,78 @@
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 { VideoBlacklist, VideoBlacklistType, 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?: VideoBlacklistType
25 }): Observable<ResultList<VideoBlacklist>> {
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 VideoBlacklistType.MANUAL
37 if (v === 'auto') return VideoBlacklistType.AUTO_BEFORE_PUBLISHED
38
39 return undefined
40 }
41 }
42 })
43
44 params = this.restService.addObjectParams(params, filters)
45 }
46 if (type) params = params.append('type', type.toString())
47
48 return this.authHttp.get<ResultList<VideoBlacklist>>(VideoBlockService.BASE_VIDEOS_URL + 'blacklist', { params })
49 .pipe(
50 map(res => this.restExtractor.convertResultListDateToHuman(res)),
51 catchError(res => this.restExtractor.handleError(res))
52 )
53 }
54
55 unblockVideo (videoIdArgs: number | number[]) {
56 const videoIds = Array.isArray(videoIdArgs) ? videoIdArgs : [ videoIdArgs ]
57
58 return observableFrom(videoIds)
59 .pipe(
60 concatMap(id => this.authHttp.delete(VideoBlockService.BASE_VIDEOS_URL + id + '/blacklist')),
61 toArray(),
62 catchError(err => this.restExtractor.handleError(err))
63 )
64 }
65
66 blockVideo (videoId: number, reason: string, unfederate: boolean) {
67 const body = {
68 unfederate,
69 reason
70 }
71
72 return this.authHttp.post(VideoBlockService.BASE_VIDEOS_URL + videoId + '/blacklist', body)
73 .pipe(
74 map(this.restExtractor.extractDataBool),
75 catchError(res => this.restExtractor.handleError(res))
76 )
77 }
78}