]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/video/video.service.ts
Add ability to set video thumbnail/preview
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.service.ts
index 3f35b67c42ab1a30190f1fa37f8dbb0c43287e27..d4f5e258f155ff2ae3b697bf21d617e6e9ecbc6c 100644 (file)
@@ -9,19 +9,19 @@ import { UserVideoRateUpdate } from '../../../../../shared/models/videos/user-vi
 import { UserVideoRate } from '../../../../../shared/models/videos/user-video-rate.model'
 import { VideoRateType } from '../../../../../shared/models/videos/video-rate.type'
 import { VideoUpdate } from '../../../../../shared/models/videos/video-update.model'
+import { environment } from '../../../environments/environment'
+import { ComponentPagination } from '../rest/component-pagination.model'
 import { RestExtractor } from '../rest/rest-extractor.service'
 import { RestService } from '../rest/rest.service'
-import { Search } from '../header/search.model'
 import { UserService } from '../users/user.service'
 import { SortField } from './sort-field.type'
 import { VideoDetails } from './video-details.model'
 import { VideoEdit } from './video-edit.model'
-import { VideoPagination } from './video-pagination.model'
 import { Video } from './video.model'
 
 @Injectable()
 export class VideoService {
-  private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
+  private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/'
 
   constructor (
     private authHttp: HttpClient,
@@ -42,17 +42,21 @@ export class VideoService {
   }
 
   updateVideo (video: VideoEdit) {
-    const language = video.language ? video.language : null
+    const language = video.language || null
+    const licence = video.licence || null
+    const category = video.category || null
+    const description = video.description || null
 
     const body: VideoUpdate = {
       name: video.name,
-      category: video.category,
-      licence: video.licence,
+      category,
+      licence,
       language,
-      description: video.description,
+      description,
       privacy: video.privacy,
       tags: video.tags,
-      nsfw: video.nsfw
+      nsfw: video.nsfw,
+      commentsEnabled: video.commentsEnabled
     }
 
     return this.authHttp.put(VideoService.BASE_VIDEO_URL + video.id, body)
@@ -68,8 +72,8 @@ export class VideoService {
       .catch(this.restExtractor.handleError)
   }
 
-  getMyVideos (videoPagination: VideoPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
-    const pagination = this.videoPaginationToRestPagination(videoPagination)
+  getMyVideos (videoPagination: ComponentPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
+    const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
 
     let params = new HttpParams()
     params = this.restService.addRestGetParams(params, pagination, sort)
@@ -79,8 +83,8 @@ export class VideoService {
       .catch((res) => this.restExtractor.handleError(res))
   }
 
-  getVideos (videoPagination: VideoPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
-    const pagination = this.videoPaginationToRestPagination(videoPagination)
+  getVideos (videoPagination: ComponentPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
+    const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
 
     let params = new HttpParams()
     params = this.restService.addRestGetParams(params, pagination, sort)
@@ -91,10 +95,14 @@ export class VideoService {
       .catch((res) => this.restExtractor.handleError(res))
   }
 
-  searchVideos (search: string, videoPagination: VideoPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
+  searchVideos (
+    search: string,
+    videoPagination: ComponentPagination,
+    sort: SortField
+  ): Observable<{ videos: Video[], totalVideos: number}> {
     const url = VideoService.BASE_VIDEO_URL + 'search'
 
-    const pagination = this.videoPaginationToRestPagination(videoPagination)
+    const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
 
     let params = new HttpParams()
     params = this.restService.addRestGetParams(params, pagination, sort)
@@ -115,7 +123,7 @@ export class VideoService {
 
   loadCompleteDescription (descriptionPath: string) {
     return this.authHttp
-      .get(API_URL + descriptionPath)
+      .get(environment.apiUrl + descriptionPath)
       .map(res => res['description'])
       .catch((res) => this.restExtractor.handleError(res))
   }
@@ -128,6 +136,10 @@ export class VideoService {
     return this.setVideoRate(id, 'dislike')
   }
 
+  unsetVideoLike (id: number) {
+    return this.setVideoRate(id, 'none')
+  }
+
   getUserVideoRating (id: number): Observable<UserVideoRate> {
     const url = UserService.BASE_USERS_URL + 'me/videos/' + id + '/rating'
 
@@ -136,13 +148,6 @@ export class VideoService {
       .catch(res => this.restExtractor.handleError(res))
   }
 
-  private videoPaginationToRestPagination (videoPagination: VideoPagination) {
-    const start: number = (videoPagination.currentPage - 1) * videoPagination.itemsPerPage
-    const count: number = videoPagination.itemsPerPage
-
-    return { start, count }
-  }
-
   private setVideoRate (id: number, rateType: VideoRateType) {
     const url = VideoService.BASE_VIDEO_URL + id + '/rate'
     const body: UserVideoRateUpdate = {