]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/shared/video.service.ts
Support roles with rights and add moderator role
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / shared / video.service.ts
index cfce4cb16d6b54ca9420c73f1a2af22e0f724ebc..8fdc1f213fae0e55aeb205ba02a9a2df7243d895 100644 (file)
@@ -12,15 +12,17 @@ import {
   UserService
 } from '../../shared'
 import { Video } from './video.model'
+import { VideoDetails } from './video-details.model'
+import { VideoEdit } from './video-edit.model'
 import { VideoPagination } from './video-pagination.model'
 import {
-  VideoCreate,
   UserVideoRate,
   VideoRateType,
   VideoUpdate,
   VideoAbuseCreate,
   UserVideoRateUpdate,
   Video as VideoServerModel,
+  VideoDetails as VideoDetailsServerModel,
   ResultList
 } from '../../../../../shared'
 
@@ -28,35 +30,19 @@ import {
 export class VideoService {
   private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
 
-  videoCategories: Array<{ id: number, label: string }> = []
-  videoLicences: Array<{ id: number, label: string }> = []
-  videoLanguages: Array<{ id: number, label: string }> = []
-
   constructor (
     private authHttp: HttpClient,
     private restExtractor: RestExtractor,
     private restService: RestService
   ) {}
 
-  loadVideoCategories () {
-    return this.loadVideoAttributeEnum('categories', this.videoCategories)
-  }
-
-  loadVideoLicences () {
-    return this.loadVideoAttributeEnum('licences', this.videoLicences)
-  }
-
-  loadVideoLanguages () {
-    return this.loadVideoAttributeEnum('languages', this.videoLanguages)
-  }
-
-  getVideo (uuid: string) {
-    return this.authHttp.get<VideoServerModel>(VideoService.BASE_VIDEO_URL + uuid)
-                        .map(videoHash => new Video(videoHash))
+  getVideo (uuid: string): Observable<VideoDetails> {
+    return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid)
+                        .map(videoHash => new VideoDetails(videoHash))
                         .catch((res) => this.restExtractor.handleError(res))
   }
 
-  updateVideo (video: Video) {
+  updateVideo (video: VideoEdit) {
     const language = video.language ? video.language : null
 
     const body: VideoUpdate = {
@@ -69,14 +55,13 @@ export class VideoService {
       nsfw: video.nsfw
     }
 
-    return this.authHttp.put(`${VideoService.BASE_VIDEO_URL}/${video.id}`, body)
+    return this.authHttp.put(VideoService.BASE_VIDEO_URL + video.id, body)
                         .map(this.restExtractor.extractDataBool)
                         .catch(this.restExtractor.handleError)
   }
 
-  // uploadVideo (video: VideoCreate) {
-  uploadVideo (video: any) {
-    const req = new HttpRequest('POST', `${VideoService.BASE_VIDEO_URL}/upload`, video, { reportProgress: true })
+  uploadVideo (video: FormData) {
+    const req = new HttpRequest('POST', VideoService.BASE_VIDEO_URL + 'upload', video, { reportProgress: true })
 
     return this.authHttp.request(req)
                         .catch(this.restExtractor.handleError)
@@ -134,18 +119,12 @@ export class VideoService {
   }
 
   getUserVideoRating (id: number): Observable<UserVideoRate> {
-    const url = UserService.BASE_USERS_URL + '/me/videos/' + id + '/rating'
+    const url = UserService.BASE_USERS_URL + 'me/videos/' + id + '/rating'
 
     return this.authHttp.get(url)
                         .catch(res => this.restExtractor.handleError(res))
   }
 
-  blacklistVideo (id: number) {
-    return this.authHttp.post(VideoService.BASE_VIDEO_URL + id + '/blacklist', {})
-                        .map(this.restExtractor.extractDataBool)
-                        .catch(res => this.restExtractor.handleError(res))
-  }
-
   private videoPaginationToRestPagination (videoPagination: VideoPagination) {
     const start: number = (videoPagination.currentPage - 1) * videoPagination.itemsPerPage
     const count: number = videoPagination.itemsPerPage
@@ -175,16 +154,4 @@ export class VideoService {
 
     return { videos, totalVideos }
   }
-
-  private loadVideoAttributeEnum (attributeName: 'categories' | 'licences' | 'languages', hashToPopulate: { id: number, label: string }[]) {
-    return this.authHttp.get(VideoService.BASE_VIDEO_URL + attributeName)
-                        .subscribe(data => {
-                          Object.keys(data).forEach(dataKey => {
-                            hashToPopulate.push({
-                              id: parseInt(dataKey, 10),
-                              label: data[dataKey]
-                            })
-                          })
-                        })
-  }
 }