diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-23 22:16:48 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-23 22:18:53 +0100 |
commit | 11ac88de40215783835cf6e6259ff0f6cee258dd (patch) | |
tree | 9bdb69c0a4e3621b9b185d30a8a63f1ac6e8fbfa /client/src/app/shared/video-abuse | |
parent | 4f8c0eb0e9356ee2782ea6eb12a92e4dc5f66127 (diff) | |
download | PeerTube-11ac88de40215783835cf6e6259ff0f6cee258dd.tar.gz PeerTube-11ac88de40215783835cf6e6259ff0f6cee258dd.tar.zst PeerTube-11ac88de40215783835cf6e6259ff0f6cee258dd.zip |
Client: add basic support to report video abuses
Diffstat (limited to 'client/src/app/shared/video-abuse')
-rw-r--r-- | client/src/app/shared/video-abuse/index.ts | 2 | ||||
-rw-r--r-- | client/src/app/shared/video-abuse/video-abuse.model.ts | 8 | ||||
-rw-r--r-- | client/src/app/shared/video-abuse/video-abuse.service.ts | 44 |
3 files changed, 54 insertions, 0 deletions
diff --git a/client/src/app/shared/video-abuse/index.ts b/client/src/app/shared/video-abuse/index.ts new file mode 100644 index 000000000..563533ba5 --- /dev/null +++ b/client/src/app/shared/video-abuse/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | export * from './video-abuse.service'; | ||
2 | export * from './video-abuse.model'; | ||
diff --git a/client/src/app/shared/video-abuse/video-abuse.model.ts b/client/src/app/shared/video-abuse/video-abuse.model.ts new file mode 100644 index 000000000..bb0373027 --- /dev/null +++ b/client/src/app/shared/video-abuse/video-abuse.model.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | export interface VideoAbuse { | ||
2 | id: string; | ||
3 | reason: string; | ||
4 | reporterPodHost: string; | ||
5 | reporterUsername: string; | ||
6 | videoId: string; | ||
7 | createdAt: Date; | ||
8 | } | ||
diff --git a/client/src/app/shared/video-abuse/video-abuse.service.ts b/client/src/app/shared/video-abuse/video-abuse.service.ts new file mode 100644 index 000000000..2750a41c7 --- /dev/null +++ b/client/src/app/shared/video-abuse/video-abuse.service.ts | |||
@@ -0,0 +1,44 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | import { Http } from '@angular/http'; | ||
3 | import { Observable } from 'rxjs/Observable'; | ||
4 | import 'rxjs/add/operator/catch'; | ||
5 | import 'rxjs/add/operator/map'; | ||
6 | |||
7 | import { AuthService } from '../core'; | ||
8 | import { AuthHttp } from '../auth'; | ||
9 | import { RestExtractor, ResultList } from '../rest'; | ||
10 | import { VideoAbuse } from './video-abuse.model'; | ||
11 | |||
12 | @Injectable() | ||
13 | export class VideoAbuseService { | ||
14 | private static BASE_VIDEO_ABUSE_URL = '/api/v1/videos/'; | ||
15 | |||
16 | constructor( | ||
17 | private authHttp: AuthHttp, | ||
18 | private restExtractor: RestExtractor | ||
19 | ) {} | ||
20 | |||
21 | getVideoAbuses() { | ||
22 | return this.authHttp.get(VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse') | ||
23 | .map(this.restExtractor.extractDataList) | ||
24 | .map(this.extractVideoAbuses) | ||
25 | } | ||
26 | |||
27 | reportVideo(id: string, reason: string) { | ||
28 | const body = { | ||
29 | reason | ||
30 | }; | ||
31 | const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'; | ||
32 | |||
33 | return this.authHttp.post(url, body) | ||
34 | .map(this.restExtractor.extractDataBool) | ||
35 | .catch((res) => this.restExtractor.handleError(res)); | ||
36 | } | ||
37 | |||
38 | private extractVideoAbuses(result: ResultList) { | ||
39 | const videoAbuses: VideoAbuse[] = result.data; | ||
40 | const totalVideoAbuses = result.total; | ||
41 | |||
42 | return { videoAbuses, totalVideoAbuses }; | ||
43 | } | ||
44 | } | ||