aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-10 10:02:18 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-10 10:18:16 +0200
commit35bf0c83c80f59ca79f4b84fac8700f17adeb22d (patch)
treea9b2106096d6ba04d7219051b17fd32cfbe6a885 /client/src/app/shared
parent769d332177a5b02d5c2ffc134687d3b4ed65bae9 (diff)
downloadPeerTube-35bf0c83c80f59ca79f4b84fac8700f17adeb22d.tar.gz
PeerTube-35bf0c83c80f59ca79f4b84fac8700f17adeb22d.tar.zst
PeerTube-35bf0c83c80f59ca79f4b84fac8700f17adeb22d.zip
Video blacklist refractoring
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/index.ts1
-rw-r--r--client/src/app/shared/shared.module.ts2
-rw-r--r--client/src/app/shared/video-blacklist/index.ts1
-rw-r--r--client/src/app/shared/video-blacklist/video-blacklist.service.ts50
4 files changed, 54 insertions, 0 deletions
diff --git a/client/src/app/shared/index.ts b/client/src/app/shared/index.ts
index 212645c51..79bf5ef43 100644
--- a/client/src/app/shared/index.ts
+++ b/client/src/app/shared/index.ts
@@ -4,5 +4,6 @@ export * from './rest'
4export * from './search' 4export * from './search'
5export * from './users' 5export * from './users'
6export * from './video-abuse' 6export * from './video-abuse'
7export * from './video-blacklist'
7export * from './shared.module' 8export * from './shared.module'
8export * from './utils' 9export * from './utils'
diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts
index 56da62fc4..47f651590 100644
--- a/client/src/app/shared/shared.module.ts
+++ b/client/src/app/shared/shared.module.ts
@@ -18,6 +18,7 @@ import { RestExtractor, RestService } from './rest'
18import { SearchComponent, SearchService } from './search' 18import { SearchComponent, SearchService } from './search'
19import { UserService } from './users' 19import { UserService } from './users'
20import { VideoAbuseService } from './video-abuse' 20import { VideoAbuseService } from './video-abuse'
21import { VideoBlacklistService } from './video-blacklist'
21 22
22@NgModule({ 23@NgModule({
23 imports: [ 24 imports: [
@@ -67,6 +68,7 @@ import { VideoAbuseService } from './video-abuse'
67 RestService, 68 RestService,
68 SearchService, 69 SearchService,
69 VideoAbuseService, 70 VideoAbuseService,
71 VideoBlacklistService,
70 UserService 72 UserService
71 ] 73 ]
72}) 74})
diff --git a/client/src/app/shared/video-blacklist/index.ts b/client/src/app/shared/video-blacklist/index.ts
new file mode 100644
index 000000000..bfb026441
--- /dev/null
+++ b/client/src/app/shared/video-blacklist/index.ts
@@ -0,0 +1 @@
export * from './video-blacklist.service'
diff --git a/client/src/app/shared/video-blacklist/video-blacklist.service.ts b/client/src/app/shared/video-blacklist/video-blacklist.service.ts
new file mode 100644
index 000000000..17373d52e
--- /dev/null
+++ b/client/src/app/shared/video-blacklist/video-blacklist.service.ts
@@ -0,0 +1,50 @@
1import { Injectable } from '@angular/core'
2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Observable } from 'rxjs/Observable'
4import 'rxjs/add/operator/catch'
5import 'rxjs/add/operator/map'
6
7import { SortMeta } from 'primeng/components/common/sortmeta'
8
9import { RestExtractor, RestPagination, RestService } from '../rest'
10import { Utils } from '../utils'
11import { BlacklistedVideo, ResultList } from '../../../../../shared'
12
13@Injectable()
14export class VideoBlacklistService {
15 private static BASE_VIDEOS_URL = API_URL + '/api/v1/videos/'
16
17 constructor (
18 private authHttp: HttpClient,
19 private restService: RestService,
20 private restExtractor: RestExtractor
21 ) {}
22
23 listBlacklist (pagination: RestPagination, sort: SortMeta): Observable<ResultList<BlacklistedVideo>> {
24 let params = new HttpParams()
25 params = this.restService.addRestGetParams(params, pagination, sort)
26
27 return this.authHttp.get<ResultList<BlacklistedVideo>>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params })
28 .map(res => this.restExtractor.convertResultListDateToHuman(res))
29 .map(res => this.restExtractor.applyToResultListData(res, this.formatBlacklistedVideo.bind(this)))
30 .catch(res => this.restExtractor.handleError(res))
31 }
32
33 removeVideoFromBlacklist (videoId: number) {
34 return this.authHttp.delete(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist')
35 .map(this.restExtractor.extractDataBool)
36 .catch(res => this.restExtractor.handleError(res))
37 }
38
39 blacklistVideo (videoId: number) {
40 return this.authHttp.post(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist', {})
41 .map(this.restExtractor.extractDataBool)
42 .catch(res => this.restExtractor.handleError(res))
43 }
44
45 private formatBlacklistedVideo (blacklistedVideo: BlacklistedVideo) {
46 return Object.assign(blacklistedVideo, {
47 createdAt: Utils.dateToHuman(blacklistedVideo.createdAt)
48 })
49 }
50}