]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Update videos response api
authorChocobozzz <me@florianbigard.com>
Mon, 19 Mar 2018 09:24:12 +0000 (10:24 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 19 Mar 2018 09:32:51 +0000 (10:32 +0100)
client/src/app/app-routing.module.ts
server/helpers/custom-validators/videos.ts
server/models/video/video.ts
shared/models/videos/video.model.ts

index c8a6b392429238fadf7d82b9d41e34fe1ead5c09..2ee3cf97436b00e45f3f489a07f27472001d3f56 100644 (file)
@@ -1,6 +1,5 @@
 import { NgModule } from '@angular/core'
-import { Routes, RouterModule } from '@angular/router'
-import { RedirectService } from '@app/core/routing/redirect.service'
+import { RouterModule, Routes } from '@angular/router'
 
 import { PreloadSelectedModulesList } from './core'
 
index a46d715ba8cf89d90b6ef4a69d9a48297ddf7d32..c08ddd24ea4e9e8187007a08a7276b170ddf9ed9 100644 (file)
@@ -26,8 +26,12 @@ function isVideoLicenceValid (value: number) {
   return value === null || VIDEO_LICENCES[value] !== undefined
 }
 
+function areVideoLanguagesValid (value: number[]) {
+  return value === null || (isArray(value) && value.every(v => isVideoLanguageValid(v)))
+}
+
 function isVideoLanguageValid (value: number) {
-  return value === null || VIDEO_LANGUAGES[value] !== undefined
+  return VIDEO_LANGUAGES[value] !== undefined
 }
 
 function isVideoDurationValid (value: string) {
@@ -133,6 +137,7 @@ export {
   isVideoDescriptionValid,
   isVideoFileInfoHashValid,
   isVideoNameValid,
+  areVideoLanguagesValid,
   isVideoTagsValid,
   isVideoAbuseReasonValid,
   isVideoFile,
index 14eb6410286873fa16ef85fadb771814686ab91a..a4d4c42f034b8da19eb4c531c71b64e9ca1d4408 100644 (file)
@@ -802,6 +802,27 @@ export class VideoModel extends Model<VideoModel> {
     return {}
   }
 
+  private static getCategoryLabel (id: number) {
+    let categoryLabel = VIDEO_CATEGORIES[id]
+    if (!categoryLabel) categoryLabel = 'Misc'
+
+    return categoryLabel
+  }
+
+  private static getLicenceLabel (id: number) {
+    let licenceLabel = VIDEO_LICENCES[id]
+    if (!licenceLabel) licenceLabel = 'Unknown'
+
+    return licenceLabel
+  }
+
+  private static getLanguageLabel (id: number) {
+    let languageLabel = VIDEO_LANGUAGES[id]
+    if (!languageLabel) languageLabel = 'Unknown'
+
+    return languageLabel
+  }
+
   getOriginalFile () {
     if (Array.isArray(this.VideoFiles) === false) return undefined
 
@@ -896,12 +917,18 @@ export class VideoModel extends Model<VideoModel> {
       id: this.id,
       uuid: this.uuid,
       name: this.name,
-      category: this.category,
-      categoryLabel: this.getCategoryLabel(),
-      licence: this.licence,
-      licenceLabel: this.getLicenceLabel(),
-      language: this.language,
-      languageLabel: this.getLanguageLabel(),
+      category: {
+        id: this.category,
+        label: VideoModel.getCategoryLabel(this.category)
+      },
+      licence: {
+        id: this.licence,
+        label: VideoModel.getLicenceLabel(this.licence)
+      },
+      language: {
+        id: this.language,
+        label: VideoModel.getLanguageLabel(this.language)
+      },
       nsfw: this.nsfw,
       description: this.getTruncatedDescription(),
       isLocal: this.isOwned(),
@@ -932,8 +959,10 @@ export class VideoModel extends Model<VideoModel> {
     if (!privacyLabel) privacyLabel = 'Unknown'
 
     const detailsJson = {
-      privacyLabel,
-      privacy: this.privacy,
+      privacy: {
+        id: this.privacy,
+        label: privacyLabel
+      },
       support: this.support,
       descriptionPath: this.getDescriptionPath(),
       channel: this.VideoChannel.toFormattedJSON(),
@@ -950,8 +979,10 @@ export class VideoModel extends Model<VideoModel> {
         let resolutionLabel = videoFile.resolution + 'p'
 
         return {
-          resolution: videoFile.resolution,
-          resolutionLabel,
+          resolution: {
+            id: videoFile.resolution,
+            label: resolutionLabel
+          },
           magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs),
           size: videoFile.size,
           torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp),
@@ -979,8 +1010,8 @@ export class VideoModel extends Model<VideoModel> {
     let language
     if (this.language) {
       language = {
-        identifier: this.language + '',
-        name: this.getLanguageLabel()
+        id: this.language + '',
+        name: VideoModel.getLanguageLabel(this.language)
       }
     }
 
@@ -988,7 +1019,7 @@ export class VideoModel extends Model<VideoModel> {
     if (this.category) {
       category = {
         identifier: this.category + '',
-        name: this.getCategoryLabel()
+        name: VideoModel.getCategoryLabel(this.category)
       }
     }
 
@@ -996,7 +1027,7 @@ export class VideoModel extends Model<VideoModel> {
     if (this.licence) {
       licence = {
         identifier: this.licence + '',
-        name: this.getLicenceLabel()
+        name: VideoModel.getLicenceLabel(this.licence)
       }
     }
 
@@ -1224,27 +1255,6 @@ export class VideoModel extends Model<VideoModel> {
     return `/api/${API_VERSION}/videos/${this.uuid}/description`
   }
 
-  getCategoryLabel () {
-    let categoryLabel = VIDEO_CATEGORIES[this.category]
-    if (!categoryLabel) categoryLabel = 'Misc'
-
-    return categoryLabel
-  }
-
-  getLicenceLabel () {
-    let licenceLabel = VIDEO_LICENCES[this.licence]
-    if (!licenceLabel) licenceLabel = 'Unknown'
-
-    return licenceLabel
-  }
-
-  getLanguageLabel () {
-    let languageLabel = VIDEO_LANGUAGES[this.language]
-    if (!languageLabel) languageLabel = 'Unknown'
-
-    return languageLabel
-  }
-
   removeThumbnail () {
     const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName())
     return unlinkPromise(thumbnailPath)
index 707cd42a71e4a137e3079bb6095c8731c00fb351..6a096195f1865a3ec07f0818494afdad8dfbdae1 100644 (file)
@@ -3,10 +3,14 @@ import { Avatar } from '../avatars/avatar.model'
 import { VideoChannel } from './video-channel.model'
 import { VideoPrivacy } from './video-privacy.enum'
 
+export interface VideoConstant <T> {
+  id: number
+  label: string
+}
+
 export interface VideoFile {
   magnetUri: string
-  resolution: number
-  resolutionLabel: string
+  resolution: VideoConstant<number>
   size: number // Bytes
   torrentUrl: string
   fileUrl: string
@@ -17,12 +21,9 @@ export interface Video {
   uuid: string
   createdAt: Date | string
   updatedAt: Date | string
-  categoryLabel: string
-  category: number
-  licenceLabel: string
-  licence: number
-  languageLabel: string
-  language: number
+  category: VideoConstant<number>
+  licence: VideoConstant<number>
+  language: VideoConstant<number>
   description: string
   duration: number
   isLocal: boolean
@@ -45,8 +46,7 @@ export interface Video {
 }
 
 export interface VideoDetails extends Video {
-  privacy: VideoPrivacy
-  privacyLabel: string
+  privacy: VideoConstant<VideoPrivacy>
   descriptionPath: string
   support: string
   channel: VideoChannel