aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-23 22:16:48 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-23 22:18:53 +0100
commit11ac88de40215783835cf6e6259ff0f6cee258dd (patch)
tree9bdb69c0a4e3621b9b185d30a8a63f1ac6e8fbfa /client/src/app/shared
parent4f8c0eb0e9356ee2782ea6eb12a92e4dc5f66127 (diff)
downloadPeerTube-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')
-rw-r--r--client/src/app/shared/forms/form-validators/index.ts2
-rw-r--r--client/src/app/shared/forms/form-validators/video-abuse.ts (renamed from client/src/app/shared/forms/form-validators/video-report.ts)2
-rw-r--r--client/src/app/shared/index.ts1
-rw-r--r--client/src/app/shared/shared.module.ts4
-rw-r--r--client/src/app/shared/video-abuse/index.ts2
-rw-r--r--client/src/app/shared/video-abuse/video-abuse.model.ts8
-rw-r--r--client/src/app/shared/video-abuse/video-abuse.service.ts44
7 files changed, 60 insertions, 3 deletions
diff --git a/client/src/app/shared/forms/form-validators/index.ts b/client/src/app/shared/forms/form-validators/index.ts
index 119b5d9bf..ab7c2df31 100644
--- a/client/src/app/shared/forms/form-validators/index.ts
+++ b/client/src/app/shared/forms/form-validators/index.ts
@@ -1,4 +1,4 @@
1export * from './host.validator'; 1export * from './host.validator';
2export * from './user'; 2export * from './user';
3export * from './video-report'; 3export * from './video-abuse';
4export * from './video'; 4export * from './video';
diff --git a/client/src/app/shared/forms/form-validators/video-report.ts b/client/src/app/shared/forms/form-validators/video-abuse.ts
index 036ee1721..94a29a3b7 100644
--- a/client/src/app/shared/forms/form-validators/video-report.ts
+++ b/client/src/app/shared/forms/form-validators/video-abuse.ts
@@ -1,6 +1,6 @@
1import { Validators } from '@angular/forms'; 1import { Validators } from '@angular/forms';
2 2
3export const VIDEO_REPORT_REASON = { 3export const VIDEO_ABUSE_REASON = {
4 VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(300) ], 4 VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(300) ],
5 MESSAGES: { 5 MESSAGES: {
6 'required': 'Report reason name is required.', 6 'required': 'Report reason name is required.',
diff --git a/client/src/app/shared/index.ts b/client/src/app/shared/index.ts
index 52a647b83..7876e6f14 100644
--- a/client/src/app/shared/index.ts
+++ b/client/src/app/shared/index.ts
@@ -3,4 +3,5 @@ export * from './forms';
3export * from './rest'; 3export * from './rest';
4export * from './search'; 4export * from './search';
5export * from './users'; 5export * from './users';
6export * from './video-abuse';
6export * from './shared.module'; 7export * from './shared.module';
diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts
index 748c5d520..7b2386d6c 100644
--- a/client/src/app/shared/shared.module.ts
+++ b/client/src/app/shared/shared.module.ts
@@ -14,6 +14,7 @@ import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload';
14import { AUTH_HTTP_PROVIDERS } from './auth'; 14import { AUTH_HTTP_PROVIDERS } from './auth';
15import { RestExtractor, RestService } from './rest'; 15import { RestExtractor, RestService } from './rest';
16import { SearchComponent, SearchService } from './search'; 16import { SearchComponent, SearchService } from './search';
17import { VideoAbuseService } from './video-abuse';
17 18
18@NgModule({ 19@NgModule({
19 imports: [ 20 imports: [
@@ -57,7 +58,8 @@ import { SearchComponent, SearchService } from './search';
57 AUTH_HTTP_PROVIDERS, 58 AUTH_HTTP_PROVIDERS,
58 RestExtractor, 59 RestExtractor,
59 RestService, 60 RestService,
60 SearchService 61 SearchService,
62 VideoAbuseService
61 ] 63 ]
62}) 64})
63export class SharedModule { } 65export class SharedModule { }
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 @@
1export * from './video-abuse.service';
2export * 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 @@
1export 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 @@
1import { Injectable } from '@angular/core';
2import { Http } from '@angular/http';
3import { Observable } from 'rxjs/Observable';
4import 'rxjs/add/operator/catch';
5import 'rxjs/add/operator/map';
6
7import { AuthService } from '../core';
8import { AuthHttp } from '../auth';
9import { RestExtractor, ResultList } from '../rest';
10import { VideoAbuse } from './video-abuse.model';
11
12@Injectable()
13export 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}