aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos/shared')
-rw-r--r--client/src/app/videos/shared/index.ts8
-rw-r--r--client/src/app/videos/shared/rate-type.type.ts2
-rw-r--r--client/src/app/videos/shared/sort-field.type.ts3
-rw-r--r--client/src/app/videos/shared/video.model.ts150
-rw-r--r--client/src/app/videos/shared/video.service.ts146
5 files changed, 154 insertions, 155 deletions
diff --git a/client/src/app/videos/shared/index.ts b/client/src/app/videos/shared/index.ts
index a68491022..0fa14f641 100644
--- a/client/src/app/videos/shared/index.ts
+++ b/client/src/app/videos/shared/index.ts
@@ -1,4 +1,4 @@
1export * from './sort-field.type'; 1export * from './sort-field.type'
2export * from './rate-type.type'; 2export * from './rate-type.type'
3export * from './video.model'; 3export * from './video.model'
4export * from './video.service'; 4export * from './video.service'
diff --git a/client/src/app/videos/shared/rate-type.type.ts b/client/src/app/videos/shared/rate-type.type.ts
index 88034d1ff..20eea3ae5 100644
--- a/client/src/app/videos/shared/rate-type.type.ts
+++ b/client/src/app/videos/shared/rate-type.type.ts
@@ -1 +1 @@
export type RateType = 'like' | 'dislike'; export type RateType = 'like' | 'dislike'
diff --git a/client/src/app/videos/shared/sort-field.type.ts b/client/src/app/videos/shared/sort-field.type.ts
index 6cc598d8b..776f360f8 100644
--- a/client/src/app/videos/shared/sort-field.type.ts
+++ b/client/src/app/videos/shared/sort-field.type.ts
@@ -2,5 +2,4 @@ export type SortField = 'name' | '-name'
2 | 'duration' | '-duration' 2 | 'duration' | '-duration'
3 | 'createdAt' | '-createdAt' 3 | 'createdAt' | '-createdAt'
4 | 'views' | '-views' 4 | 'views' | '-views'
5 | 'likes' | '-likes'; 5 | 'likes' | '-likes'
6
diff --git a/client/src/app/videos/shared/video.model.ts b/client/src/app/videos/shared/video.model.ts
index e897eb175..f5e16fc13 100644
--- a/client/src/app/videos/shared/video.model.ts
+++ b/client/src/app/videos/shared/video.model.ts
@@ -1,56 +1,56 @@
1import { Video as VideoServerModel } from '../../../../../shared'; 1import { Video as VideoServerModel } from '../../../../../shared'
2import { User } from '../../shared'; 2import { User } from '../../shared'
3 3
4export class Video implements VideoServerModel { 4export class Video implements VideoServerModel {
5 author: string; 5 author: string
6 by: string; 6 by: string
7 createdAt: Date; 7 createdAt: Date
8 categoryLabel: string; 8 categoryLabel: string
9 category: number; 9 category: number
10 licenceLabel: string; 10 licenceLabel: string
11 licence: number; 11 licence: number
12 languageLabel: string; 12 languageLabel: string
13 language: number; 13 language: number
14 description: string; 14 description: string
15 duration: number; 15 duration: number
16 durationLabel: string; 16 durationLabel: string
17 id: string; 17 id: string
18 isLocal: boolean; 18 isLocal: boolean
19 magnetUri: string; 19 magnetUri: string
20 name: string; 20 name: string
21 podHost: string; 21 podHost: string
22 tags: string[]; 22 tags: string[]
23 thumbnailPath: string; 23 thumbnailPath: string
24 thumbnailUrl: string; 24 thumbnailUrl: string
25 views: number; 25 views: number
26 likes: number; 26 likes: number
27 dislikes: number; 27 dislikes: number
28 nsfw: boolean; 28 nsfw: boolean
29 29
30 private static createByString(author: string, podHost: string) { 30 private static createByString (author: string, podHost: string) {
31 return author + '@' + podHost; 31 return author + '@' + podHost
32 } 32 }
33 33
34 private static createDurationString(duration: number) { 34 private static createDurationString (duration: number) {
35 const minutes = Math.floor(duration / 60); 35 const minutes = Math.floor(duration / 60)
36 const seconds = duration % 60; 36 const seconds = duration % 60
37 const minutes_padding = minutes >= 10 ? '' : '0'; 37 const minutesPadding = minutes >= 10 ? '' : '0'
38 const seconds_padding = seconds >= 10 ? '' : '0'; 38 const secondsPadding = seconds >= 10 ? '' : '0'
39 39
40 return minutes_padding + minutes.toString() + ':' + seconds_padding + seconds.toString(); 40 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
41 } 41 }
42 42
43 constructor(hash: { 43 constructor (hash: {
44 author: string, 44 author: string,
45 createdAt: string, 45 createdAt: string,
46 categoryLabel: string, 46 categoryLabel: string,
47 category: number, 47 category: number,
48 licenceLabel: string, 48 licenceLabel: string,
49 licence: number, 49 licence: number,
50 languageLabel: string; 50 languageLabel: string
51 language: number; 51 language: number
52 description: string, 52 description: string,
53 duration: number; 53 duration: number
54 id: string, 54 id: string,
55 isLocal: boolean, 55 isLocal: boolean,
56 magnetUri: string, 56 magnetUri: string,
@@ -63,57 +63,57 @@ export class Video implements VideoServerModel {
63 dislikes: number, 63 dislikes: number,
64 nsfw: boolean 64 nsfw: boolean
65 }) { 65 }) {
66 this.author = hash.author; 66 this.author = hash.author
67 this.createdAt = new Date(hash.createdAt); 67 this.createdAt = new Date(hash.createdAt)
68 this.categoryLabel = hash.categoryLabel; 68 this.categoryLabel = hash.categoryLabel
69 this.category = hash.category; 69 this.category = hash.category
70 this.licenceLabel = hash.licenceLabel; 70 this.licenceLabel = hash.licenceLabel
71 this.licence = hash.licence; 71 this.licence = hash.licence
72 this.languageLabel = hash.languageLabel; 72 this.languageLabel = hash.languageLabel
73 this.language = hash.language; 73 this.language = hash.language
74 this.description = hash.description; 74 this.description = hash.description
75 this.duration = hash.duration; 75 this.duration = hash.duration
76 this.durationLabel = Video.createDurationString(hash.duration); 76 this.durationLabel = Video.createDurationString(hash.duration)
77 this.id = hash.id; 77 this.id = hash.id
78 this.isLocal = hash.isLocal; 78 this.isLocal = hash.isLocal
79 this.magnetUri = hash.magnetUri; 79 this.magnetUri = hash.magnetUri
80 this.name = hash.name; 80 this.name = hash.name
81 this.podHost = hash.podHost; 81 this.podHost = hash.podHost
82 this.tags = hash.tags; 82 this.tags = hash.tags
83 this.thumbnailPath = hash.thumbnailPath; 83 this.thumbnailPath = hash.thumbnailPath
84 this.thumbnailUrl = API_URL + hash.thumbnailPath; 84 this.thumbnailUrl = API_URL + hash.thumbnailPath
85 this.views = hash.views; 85 this.views = hash.views
86 this.likes = hash.likes; 86 this.likes = hash.likes
87 this.dislikes = hash.dislikes; 87 this.dislikes = hash.dislikes
88 this.nsfw = hash.nsfw; 88 this.nsfw = hash.nsfw
89 89
90 this.by = Video.createByString(hash.author, hash.podHost); 90 this.by = Video.createByString(hash.author, hash.podHost)
91 } 91 }
92 92
93 isRemovableBy(user) { 93 isRemovableBy (user) {
94 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true); 94 return user && this.isLocal === true && (this.author === user.username || user.isAdmin() === true)
95 } 95 }
96 96
97 isBlackistableBy(user) { 97 isBlackistableBy (user) {
98 return user && user.isAdmin() === true && this.isLocal === false; 98 return user && user.isAdmin() === true && this.isLocal === false
99 } 99 }
100 100
101 isUpdatableBy(user) { 101 isUpdatableBy (user) {
102 return user && this.isLocal === true && user.username === this.author; 102 return user && this.isLocal === true && user.username === this.author
103 } 103 }
104 104
105 isVideoNSFWForUser(user: User) { 105 isVideoNSFWForUser (user: User) {
106 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos... 106 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
107 return (this.nsfw && (!user || user.displayNSFW === false)); 107 return (this.nsfw && (!user || user.displayNSFW === false))
108 } 108 }
109 109
110 patch(values: Object) { 110 patch (values: Object) {
111 Object.keys(values).forEach((key) => { 111 Object.keys(values).forEach((key) => {
112 this[key] = values[key]; 112 this[key] = values[key]
113 }); 113 })
114 } 114 }
115 115
116 toJSON() { 116 toJSON () {
117 return { 117 return {
118 author: this.author, 118 author: this.author,
119 createdAt: this.createdAt, 119 createdAt: this.createdAt,
@@ -133,6 +133,6 @@ export class Video implements VideoServerModel {
133 likes: this.likes, 133 likes: this.likes,
134 dislikes: this.dislikes, 134 dislikes: this.dislikes,
135 nsfw: this.nsfw 135 nsfw: this.nsfw
136 }; 136 }
137 } 137 }
138} 138}
diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts
index a53ea1064..a4e3d16df 100644
--- a/client/src/app/videos/shared/video.service.ts
+++ b/client/src/app/videos/shared/video.service.ts
@@ -1,13 +1,13 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { Http, Headers, RequestOptions } from '@angular/http'; 2import { Http, Headers, RequestOptions } from '@angular/http'
3import { Observable } from 'rxjs/Observable'; 3import { Observable } from 'rxjs/Observable'
4import 'rxjs/add/operator/catch'; 4import 'rxjs/add/operator/catch'
5import 'rxjs/add/operator/map'; 5import 'rxjs/add/operator/map'
6 6
7import { Search } from '../../shared'; 7import { Search } from '../../shared'
8import { SortField } from './sort-field.type'; 8import { SortField } from './sort-field.type'
9import { RateType } from './rate-type.type'; 9import { RateType } from './rate-type.type'
10import { AuthService } from '../../core'; 10import { AuthService } from '../../core'
11import { 11import {
12 AuthHttp, 12 AuthHttp,
13 RestExtractor, 13 RestExtractor,
@@ -15,18 +15,18 @@ import {
15 RestService, 15 RestService,
16 ResultList, 16 ResultList,
17 UserService 17 UserService
18} from '../../shared'; 18} from '../../shared'
19import { Video } from './video.model'; 19import { Video } from './video.model'
20 20
21@Injectable() 21@Injectable()
22export class VideoService { 22export class VideoService {
23 private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'; 23 private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
24 24
25 videoCategories: Array<{ id: number, label: string }> = []; 25 videoCategories: Array<{ id: number, label: string }> = []
26 videoLicences: Array<{ id: number, label: string }> = []; 26 videoLicences: Array<{ id: number, label: string }> = []
27 videoLanguages: Array<{ id: number, label: string }> = []; 27 videoLanguages: Array<{ id: number, label: string }> = []
28 28
29 constructor( 29 constructor (
30 private authService: AuthService, 30 private authService: AuthService,
31 private authHttp: AuthHttp, 31 private authHttp: AuthHttp,
32 private http: Http, 32 private http: Http,
@@ -34,54 +34,54 @@ export class VideoService {
34 private restService: RestService 34 private restService: RestService
35 ) {} 35 ) {}
36 36
37 loadVideoCategories() { 37 loadVideoCategories () {
38 return this.http.get(VideoService.BASE_VIDEO_URL + 'categories') 38 return this.http.get(VideoService.BASE_VIDEO_URL + 'categories')
39 .map(this.restExtractor.extractDataGet) 39 .map(this.restExtractor.extractDataGet)
40 .subscribe(data => { 40 .subscribe(data => {
41 Object.keys(data).forEach(categoryKey => { 41 Object.keys(data).forEach(categoryKey => {
42 this.videoCategories.push({ 42 this.videoCategories.push({
43 id: parseInt(categoryKey), 43 id: parseInt(categoryKey, 10),
44 label: data[categoryKey] 44 label: data[categoryKey]
45 }); 45 })
46 }); 46 })
47 }); 47 })
48 } 48 }
49 49
50 loadVideoLicences() { 50 loadVideoLicences () {
51 return this.http.get(VideoService.BASE_VIDEO_URL + 'licences') 51 return this.http.get(VideoService.BASE_VIDEO_URL + 'licences')
52 .map(this.restExtractor.extractDataGet) 52 .map(this.restExtractor.extractDataGet)
53 .subscribe(data => { 53 .subscribe(data => {
54 Object.keys(data).forEach(licenceKey => { 54 Object.keys(data).forEach(licenceKey => {
55 this.videoLicences.push({ 55 this.videoLicences.push({
56 id: parseInt(licenceKey), 56 id: parseInt(licenceKey, 10),
57 label: data[licenceKey] 57 label: data[licenceKey]
58 }); 58 })
59 }); 59 })
60 }); 60 })
61 } 61 }
62 62
63 loadVideoLanguages() { 63 loadVideoLanguages () {
64 return this.http.get(VideoService.BASE_VIDEO_URL + 'languages') 64 return this.http.get(VideoService.BASE_VIDEO_URL + 'languages')
65 .map(this.restExtractor.extractDataGet) 65 .map(this.restExtractor.extractDataGet)
66 .subscribe(data => { 66 .subscribe(data => {
67 Object.keys(data).forEach(languageKey => { 67 Object.keys(data).forEach(languageKey => {
68 this.videoLanguages.push({ 68 this.videoLanguages.push({
69 id: parseInt(languageKey), 69 id: parseInt(languageKey, 10),
70 label: data[languageKey] 70 label: data[languageKey]
71 }); 71 })
72 }); 72 })
73 }); 73 })
74 } 74 }
75 75
76 getVideo(id: string): Observable<Video> { 76 getVideo (id: string): Observable<Video> {
77 return this.http.get(VideoService.BASE_VIDEO_URL + id) 77 return this.http.get(VideoService.BASE_VIDEO_URL + id)
78 .map(this.restExtractor.extractDataGet) 78 .map(this.restExtractor.extractDataGet)
79 .map(video_hash => new Video(video_hash)) 79 .map(videoHash => new Video(videoHash))
80 .catch((res) => this.restExtractor.handleError(res)); 80 .catch((res) => this.restExtractor.handleError(res))
81 } 81 }
82 82
83 updateVideo(video: Video) { 83 updateVideo (video: Video) {
84 const language = video.language ? video.language : null; 84 const language = video.language ? video.language : null
85 85
86 const body = { 86 const body = {
87 name: video.name, 87 name: video.name,
@@ -90,94 +90,94 @@ export class VideoService {
90 language, 90 language,
91 description: video.description, 91 description: video.description,
92 tags: video.tags 92 tags: video.tags
93 }; 93 }
94 94
95 const headers = new Headers({ 'Content-Type': 'application/json' }); 95 const headers = new Headers({ 'Content-Type': 'application/json' })
96 const options = new RequestOptions({ headers: headers }); 96 const options = new RequestOptions({ headers: headers })
97 97
98 return this.authHttp.put(`${VideoService.BASE_VIDEO_URL}/${video.id}`, body, options) 98 return this.authHttp.put(`${VideoService.BASE_VIDEO_URL}/${video.id}`, body, options)
99 .map(this.restExtractor.extractDataBool) 99 .map(this.restExtractor.extractDataBool)
100 .catch(this.restExtractor.handleError); 100 .catch(this.restExtractor.handleError)
101 } 101 }
102 102
103 getVideos(pagination: RestPagination, sort: SortField) { 103 getVideos (pagination: RestPagination, sort: SortField) {
104 const params = this.restService.buildRestGetParams(pagination, sort); 104 const params = this.restService.buildRestGetParams(pagination, sort)
105 105
106 return this.http.get(VideoService.BASE_VIDEO_URL, { search: params }) 106 return this.http.get(VideoService.BASE_VIDEO_URL, { search: params })
107 .map(res => res.json()) 107 .map(res => res.json())
108 .map(this.extractVideos) 108 .map(this.extractVideos)
109 .catch((res) => this.restExtractor.handleError(res)); 109 .catch((res) => this.restExtractor.handleError(res))
110 } 110 }
111 111
112 removeVideo(id: string) { 112 removeVideo (id: string) {
113 return this.authHttp.delete(VideoService.BASE_VIDEO_URL + id) 113 return this.authHttp.delete(VideoService.BASE_VIDEO_URL + id)
114 .map(this.restExtractor.extractDataBool) 114 .map(this.restExtractor.extractDataBool)
115 .catch((res) => this.restExtractor.handleError(res)); 115 .catch((res) => this.restExtractor.handleError(res))
116 } 116 }
117 117
118 searchVideos(search: Search, pagination: RestPagination, sort: SortField) { 118 searchVideos (search: Search, pagination: RestPagination, sort: SortField) {
119 const params = this.restService.buildRestGetParams(pagination, sort); 119 const params = this.restService.buildRestGetParams(pagination, sort)
120 120
121 if (search.field) params.set('field', search.field); 121 if (search.field) params.set('field', search.field)
122 122
123 return this.http.get(VideoService.BASE_VIDEO_URL + 'search/' + encodeURIComponent(search.value), { search: params }) 123 return this.http.get(VideoService.BASE_VIDEO_URL + 'search/' + encodeURIComponent(search.value), { search: params })
124 .map(this.restExtractor.extractDataList) 124 .map(this.restExtractor.extractDataList)
125 .map(this.extractVideos) 125 .map(this.extractVideos)
126 .catch((res) => this.restExtractor.handleError(res)); 126 .catch((res) => this.restExtractor.handleError(res))
127 } 127 }
128 128
129 reportVideo(id: string, reason: string) { 129 reportVideo (id: string, reason: string) {
130 const url = VideoService.BASE_VIDEO_URL + id + '/abuse'; 130 const url = VideoService.BASE_VIDEO_URL + id + '/abuse'
131 const body = { 131 const body = {
132 reason 132 reason
133 }; 133 }
134 134
135 return this.authHttp.post(url, body) 135 return this.authHttp.post(url, body)
136 .map(this.restExtractor.extractDataBool) 136 .map(this.restExtractor.extractDataBool)
137 .catch((res) => this.restExtractor.handleError(res)); 137 .catch((res) => this.restExtractor.handleError(res))
138 } 138 }
139 139
140 setVideoLike(id: string) { 140 setVideoLike (id: string) {
141 return this.setVideoRate(id, 'like'); 141 return this.setVideoRate(id, 'like')
142 } 142 }
143 143
144 setVideoDislike(id: string) { 144 setVideoDislike (id: string) {
145 return this.setVideoRate(id, 'dislike'); 145 return this.setVideoRate(id, 'dislike')
146 } 146 }
147 147
148 getUserVideoRating(id: string) { 148 getUserVideoRating (id: string) {
149 const url = UserService.BASE_USERS_URL + '/me/videos/' + id + '/rating'; 149 const url = UserService.BASE_USERS_URL + '/me/videos/' + id + '/rating'
150 150
151 return this.authHttp.get(url) 151 return this.authHttp.get(url)
152 .map(this.restExtractor.extractDataGet) 152 .map(this.restExtractor.extractDataGet)
153 .catch((res) => this.restExtractor.handleError(res)); 153 .catch((res) => this.restExtractor.handleError(res))
154 } 154 }
155 155
156 blacklistVideo(id: string) { 156 blacklistVideo (id: string) {
157 return this.authHttp.post(VideoService.BASE_VIDEO_URL + id + '/blacklist', {}) 157 return this.authHttp.post(VideoService.BASE_VIDEO_URL + id + '/blacklist', {})
158 .map(this.restExtractor.extractDataBool) 158 .map(this.restExtractor.extractDataBool)
159 .catch((res) => this.restExtractor.handleError(res)); 159 .catch((res) => this.restExtractor.handleError(res))
160 } 160 }
161 161
162 private setVideoRate(id: string, rateType: RateType) { 162 private setVideoRate (id: string, rateType: RateType) {
163 const url = VideoService.BASE_VIDEO_URL + id + '/rate'; 163 const url = VideoService.BASE_VIDEO_URL + id + '/rate'
164 const body = { 164 const body = {
165 rating: rateType 165 rating: rateType
166 }; 166 }
167 167
168 return this.authHttp.put(url, body) 168 return this.authHttp.put(url, body)
169 .map(this.restExtractor.extractDataBool) 169 .map(this.restExtractor.extractDataBool)
170 .catch((res) => this.restExtractor.handleError(res)); 170 .catch((res) => this.restExtractor.handleError(res))
171 } 171 }
172 172
173 private extractVideos(result: ResultList) { 173 private extractVideos (result: ResultList) {
174 const videosJson = result.data; 174 const videosJson = result.data
175 const totalVideos = result.total; 175 const totalVideos = result.total
176 const videos = []; 176 const videos = []
177 for (const videoJson of videosJson) { 177 for (const videoJson of videosJson) {
178 videos.push(new Video(videoJson)); 178 videos.push(new Video(videoJson))
179 } 179 }
180 180
181 return { videos, totalVideos }; 181 return { videos, totalVideos }
182 } 182 }
183} 183}