]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/shared/video.service.ts
Format video blacklist
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video.service.ts
index 15f017e33d3b92c395441d0e442349283e657d52..ba83c72fd12a8933e630399f1d17627d71cc625b 100644 (file)
@@ -1,5 +1,5 @@
 import { Injectable } from '@angular/core';
-import { Http } from '@angular/http';
+import { Http, Headers, RequestOptions } from '@angular/http';
 import { Observable } from 'rxjs/Observable';
 import 'rxjs/add/operator/catch';
 import 'rxjs/add/operator/map';
@@ -24,6 +24,7 @@ export class VideoService {
 
   videoCategories: Array<{ id: number, label: string }> = [];
   videoLicences: Array<{ id: number, label: string }> = [];
+  videoLanguages: Array<{ id: number, label: string }> = [];
 
   constructor(
     private authService: AuthService,
@@ -59,6 +60,19 @@ export class VideoService {
                     });
   }
 
+  loadVideoLanguages() {
+    return this.http.get(VideoService.BASE_VIDEO_URL + 'languages')
+                    .map(this.restExtractor.extractDataGet)
+                    .subscribe(data => {
+                      Object.keys(data).forEach(languageKey => {
+                        this.videoLanguages.push({
+                          id: parseInt(languageKey),
+                          label: data[languageKey]
+                        });
+                      });
+                    });
+  }
+
   getVideo(id: string): Observable<Video> {
     return this.http.get(VideoService.BASE_VIDEO_URL + id)
                     .map(this.restExtractor.extractDataGet)
@@ -66,6 +80,23 @@ export class VideoService {
                     .catch((res) => this.restExtractor.handleError(res));
   }
 
+  updateVideo(video: Video) {
+    const body = {
+      name: video.name,
+      category: video.category,
+      licence: video.licence,
+      language: video.language,
+      description: video.description,
+      tags: video.tags
+    };
+    const headers = new Headers({ 'Content-Type': 'application/json' });
+    const options = new RequestOptions({ headers: headers });
+
+    return this.authHttp.put(`${VideoService.BASE_VIDEO_URL}/${video.id}`, body, options)
+                        .map(this.restExtractor.extractDataBool)
+                        .catch(this.restExtractor.handleError);
+  }
+
   getVideos(pagination: RestPagination, sort: SortField) {
     const params = this.restService.buildRestGetParams(pagination, sort);
 
@@ -119,6 +150,12 @@ export class VideoService {
                         .catch((res) => this.restExtractor.handleError(res));
   }
 
+  blacklistVideo(id: string) {
+    return this.authHttp.post(VideoService.BASE_VIDEO_URL + id + '/blacklist', {})
+                        .map(this.restExtractor.extractDataBool)
+                        .catch((res) => this.restExtractor.handleError(res));
+  }
+
   private setVideoRate(id: string, rateType: RateType) {
     const url = VideoService.BASE_VIDEO_URL + id + '/rate';
     const body = {