diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-05-21 18:03:34 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-05-21 18:08:23 +0200 |
commit | 501bc6c2b186f6a724a5b619d15aa44791f13995 (patch) | |
tree | 4a6e1d244c5f94305a25b6ec6f50f1a71ce9295d /client/angular/videos/videos.service.ts | |
parent | 295ba044afc394ef51dac22263063670362787ec (diff) | |
download | PeerTube-501bc6c2b186f6a724a5b619d15aa44791f13995.tar.gz PeerTube-501bc6c2b186f6a724a5b619d15aa44791f13995.tar.zst PeerTube-501bc6c2b186f6a724a5b619d15aa44791f13995.zip |
Thumbnail, author and duration support in client
Diffstat (limited to 'client/angular/videos/videos.service.ts')
-rw-r--r-- | client/angular/videos/videos.service.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/client/angular/videos/videos.service.ts b/client/angular/videos/videos.service.ts new file mode 100644 index 000000000..f4790b511 --- /dev/null +++ b/client/angular/videos/videos.service.ts | |||
@@ -0,0 +1,54 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | import { Http, Response } from '@angular/http'; | ||
3 | import { Observable } from 'rxjs/Rx'; | ||
4 | |||
5 | import { Video } from './video'; | ||
6 | import { AuthService } from '../users/services/auth.service'; | ||
7 | |||
8 | @Injectable() | ||
9 | export class VideosService { | ||
10 | private _baseVideoUrl = '/api/v1/videos/'; | ||
11 | |||
12 | constructor (private http: Http, private _authService: AuthService) {} | ||
13 | |||
14 | getVideos() { | ||
15 | return this.http.get(this._baseVideoUrl) | ||
16 | .map(res => res.json()) | ||
17 | .map(this.extractVideos) | ||
18 | .catch(this.handleError); | ||
19 | } | ||
20 | |||
21 | getVideo(id: string) { | ||
22 | return this.http.get(this._baseVideoUrl + id) | ||
23 | .map(res => <Video> res.json()) | ||
24 | .catch(this.handleError); | ||
25 | } | ||
26 | |||
27 | removeVideo(id: string) { | ||
28 | const options = this._authService.getAuthRequestOptions(); | ||
29 | return this.http.delete(this._baseVideoUrl + id, options) | ||
30 | .map(res => <number> res.status) | ||
31 | .catch(this.handleError); | ||
32 | } | ||
33 | |||
34 | searchVideos(search: string) { | ||
35 | return this.http.get(this._baseVideoUrl + 'search/' + search) | ||
36 | .map(res => res.json()) | ||
37 | .map(this.extractVideos) | ||
38 | .catch(this.handleError); | ||
39 | } | ||
40 | |||
41 | private extractVideos (body: any[]) { | ||
42 | const videos = []; | ||
43 | for (const video_json of body) { | ||
44 | videos.push(new Video(video_json)); | ||
45 | } | ||
46 | |||
47 | return videos; | ||
48 | } | ||
49 | |||
50 | private handleError (error: Response) { | ||
51 | console.error(error); | ||
52 | return Observable.throw(error.json().error || 'Server error'); | ||
53 | } | ||
54 | } | ||