]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/app/videos/shared/video.service.ts
Move webtorrent inside a service
[github/Chocobozzz/PeerTube.git] / client / app / videos / shared / video.service.ts
index b6e0800a073f3f91eb9c518ea1c4268b720652f3..7b6519f007a01f807f7c4f9a83ff6b377a1b9106 100644 (file)
@@ -12,7 +12,16 @@ import { Video } from './video.model';
 export class VideoService {
   private static BASE_VIDEO_URL = '/api/v1/videos/';
 
-  constructor(private http: Http, private authService: AuthService) {}
+  constructor(
+    private authService: AuthService,
+    private http: Http
+  ) {}
+
+  getVideo(id: string) {
+    return this.http.get(VideoService.BASE_VIDEO_URL + id)
+                    .map(res => <Video> res.json())
+                    .catch(this.handleError);
+  }
 
   getVideos(pagination: Pagination, sort: SortField) {
     const params = this.createPaginationParams(pagination);
@@ -25,12 +34,6 @@ export class VideoService {
                     .catch(this.handleError);
   }
 
-  getVideo(id: string) {
-    return this.http.get(VideoService.BASE_VIDEO_URL + id)
-                    .map(res => <Video> res.json())
-                    .catch(this.handleError);
-  }
-
   removeVideo(id: string) {
     const options = this.authService.getAuthRequestOptions();
     return this.http.delete(VideoService.BASE_VIDEO_URL + id, options)
@@ -50,6 +53,17 @@ export class VideoService {
                     .catch(this.handleError);
   }
 
+  private createPaginationParams(pagination: Pagination) {
+    const params = new URLSearchParams();
+    const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage;
+    const count: number = pagination.itemsPerPage;
+
+    params.set('start', start.toString());
+    params.set('count', count.toString());
+
+    return params;
+  }
+
   private extractVideos(body: any) {
     const videos_json = body.data;
     const totalVideos = body.total;
@@ -65,15 +79,4 @@ export class VideoService {
     console.error(error);
     return Observable.throw(error.json().error || 'Server error');
   }
-
-  private createPaginationParams(pagination: Pagination) {
-    const params = new URLSearchParams();
-    const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage;
-    const count: number = pagination.itemsPerPage;
-
-    params.set('start', start.toString());
-    params.set('count', count.toString());
-
-    return params;
-  }
 }