aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/angular/videos/videos.service.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-27 16:23:10 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-27 16:23:10 +0200
commit41a2aee38cf812510010da09de9bae53590ec119 (patch)
tree79d55d6ae0ef6f66ccb88890cf1ef1946dc65fb4 /client/angular/videos/videos.service.ts
parent157cb9c9713e08ff70078660a32dd77ecb87eabc (diff)
downloadPeerTube-41a2aee38cf812510010da09de9bae53590ec119.tar.gz
PeerTube-41a2aee38cf812510010da09de9bae53590ec119.tar.zst
PeerTube-41a2aee38cf812510010da09de9bae53590ec119.zip
Follow the angular styleguide for the directories structure
Diffstat (limited to 'client/angular/videos/videos.service.ts')
-rw-r--r--client/angular/videos/videos.service.ts79
1 files changed, 0 insertions, 79 deletions
diff --git a/client/angular/videos/videos.service.ts b/client/angular/videos/videos.service.ts
deleted file mode 100644
index d5438fd82..000000000
--- a/client/angular/videos/videos.service.ts
+++ /dev/null
@@ -1,79 +0,0 @@
1import { Injectable } from '@angular/core';
2import { Http, Response, URLSearchParams } from '@angular/http';
3import { Observable } from 'rxjs/Rx';
4
5import { Pagination } from './pagination';
6import { Video } from './video';
7import { AuthService } from '../users/services/auth.service';
8import { Search } from '../app/search';
9import { SortField } from './components/list/sort';
10
11@Injectable()
12export class VideosService {
13 private _baseVideoUrl = '/api/v1/videos/';
14
15 constructor (private http: Http, private _authService: AuthService) {}
16
17 getVideos(pagination: Pagination, sort: SortField) {
18 const params = this.createPaginationParams(pagination);
19
20 if (sort) params.set('sort', sort);
21
22 return this.http.get(this._baseVideoUrl, { search: params })
23 .map(res => res.json())
24 .map(this.extractVideos)
25 .catch(this.handleError);
26 }
27
28 getVideo(id: string) {
29 return this.http.get(this._baseVideoUrl + id)
30 .map(res => <Video> res.json())
31 .catch(this.handleError);
32 }
33
34 removeVideo(id: string) {
35 const options = this._authService.getAuthRequestOptions();
36 return this.http.delete(this._baseVideoUrl + id, options)
37 .map(res => <number> res.status)
38 .catch(this.handleError);
39 }
40
41 searchVideos(search: Search, pagination: Pagination, sort: SortField) {
42 const params = this.createPaginationParams(pagination);
43
44 if (search.field) params.set('field', search.field);
45 if (sort) params.set('sort', sort);
46
47 return this.http.get(this._baseVideoUrl + 'search/' + encodeURIComponent(search.value), { search: params })
48 .map(res => res.json())
49 .map(this.extractVideos)
50 .catch(this.handleError);
51 }
52
53 private extractVideos (body: any) {
54 const videos_json = body.data;
55 const totalVideos = body.total;
56 const videos = [];
57 for (const video_json of videos_json) {
58 videos.push(new Video(video_json));
59 }
60
61 return { videos, totalVideos };
62 }
63
64 private handleError (error: Response) {
65 console.error(error);
66 return Observable.throw(error.json().error || 'Server error');
67 }
68
69 private createPaginationParams(pagination: Pagination) {
70 const params = new URLSearchParams();
71 const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage;
72 const count: number = pagination.itemsPerPage;
73
74 params.set('start', start.toString());
75 params.set('count', count.toString());
76
77 return params;
78 }
79}