diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-10 10:02:18 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-10 10:18:16 +0200 |
commit | 35bf0c83c80f59ca79f4b84fac8700f17adeb22d (patch) | |
tree | a9b2106096d6ba04d7219051b17fd32cfbe6a885 /client/src/app/shared | |
parent | 769d332177a5b02d5c2ffc134687d3b4ed65bae9 (diff) | |
download | PeerTube-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.ts | 1 | ||||
-rw-r--r-- | client/src/app/shared/shared.module.ts | 2 | ||||
-rw-r--r-- | client/src/app/shared/video-blacklist/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/shared/video-blacklist/video-blacklist.service.ts | 50 |
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' | |||
4 | export * from './search' | 4 | export * from './search' |
5 | export * from './users' | 5 | export * from './users' |
6 | export * from './video-abuse' | 6 | export * from './video-abuse' |
7 | export * from './video-blacklist' | ||
7 | export * from './shared.module' | 8 | export * from './shared.module' |
8 | export * from './utils' | 9 | export * 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' | |||
18 | import { SearchComponent, SearchService } from './search' | 18 | import { SearchComponent, SearchService } from './search' |
19 | import { UserService } from './users' | 19 | import { UserService } from './users' |
20 | import { VideoAbuseService } from './video-abuse' | 20 | import { VideoAbuseService } from './video-abuse' |
21 | import { 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 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
3 | import { Observable } from 'rxjs/Observable' | ||
4 | import 'rxjs/add/operator/catch' | ||
5 | import 'rxjs/add/operator/map' | ||
6 | |||
7 | import { SortMeta } from 'primeng/components/common/sortmeta' | ||
8 | |||
9 | import { RestExtractor, RestPagination, RestService } from '../rest' | ||
10 | import { Utils } from '../utils' | ||
11 | import { BlacklistedVideo, ResultList } from '../../../../../shared' | ||
12 | |||
13 | @Injectable() | ||
14 | export 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 | } | ||