1
0
Fork 0

Update videos response api

This commit is contained in:
Chocobozzz 2018-03-19 10:24:12 +01:00
parent f47776e265
commit ae5a3dd664
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 62 additions and 48 deletions

View File

@ -1,6 +1,5 @@
import { NgModule } from '@angular/core' import { NgModule } from '@angular/core'
import { Routes, RouterModule } from '@angular/router' import { RouterModule, Routes } from '@angular/router'
import { RedirectService } from '@app/core/routing/redirect.service'
import { PreloadSelectedModulesList } from './core' import { PreloadSelectedModulesList } from './core'

View File

@ -26,8 +26,12 @@ function isVideoLicenceValid (value: number) {
return value === null || VIDEO_LICENCES[value] !== undefined 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) { function isVideoLanguageValid (value: number) {
return value === null || VIDEO_LANGUAGES[value] !== undefined return VIDEO_LANGUAGES[value] !== undefined
} }
function isVideoDurationValid (value: string) { function isVideoDurationValid (value: string) {
@ -133,6 +137,7 @@ export {
isVideoDescriptionValid, isVideoDescriptionValid,
isVideoFileInfoHashValid, isVideoFileInfoHashValid,
isVideoNameValid, isVideoNameValid,
areVideoLanguagesValid,
isVideoTagsValid, isVideoTagsValid,
isVideoAbuseReasonValid, isVideoAbuseReasonValid,
isVideoFile, isVideoFile,

View File

@ -802,6 +802,27 @@ export class VideoModel extends Model<VideoModel> {
return {} 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 () { getOriginalFile () {
if (Array.isArray(this.VideoFiles) === false) return undefined if (Array.isArray(this.VideoFiles) === false) return undefined
@ -896,12 +917,18 @@ export class VideoModel extends Model<VideoModel> {
id: this.id, id: this.id,
uuid: this.uuid, uuid: this.uuid,
name: this.name, name: this.name,
category: this.category, category: {
categoryLabel: this.getCategoryLabel(), id: this.category,
licence: this.licence, label: VideoModel.getCategoryLabel(this.category)
licenceLabel: this.getLicenceLabel(), },
language: this.language, licence: {
languageLabel: this.getLanguageLabel(), id: this.licence,
label: VideoModel.getLicenceLabel(this.licence)
},
language: {
id: this.language,
label: VideoModel.getLanguageLabel(this.language)
},
nsfw: this.nsfw, nsfw: this.nsfw,
description: this.getTruncatedDescription(), description: this.getTruncatedDescription(),
isLocal: this.isOwned(), isLocal: this.isOwned(),
@ -932,8 +959,10 @@ export class VideoModel extends Model<VideoModel> {
if (!privacyLabel) privacyLabel = 'Unknown' if (!privacyLabel) privacyLabel = 'Unknown'
const detailsJson = { const detailsJson = {
privacyLabel, privacy: {
privacy: this.privacy, id: this.privacy,
label: privacyLabel
},
support: this.support, support: this.support,
descriptionPath: this.getDescriptionPath(), descriptionPath: this.getDescriptionPath(),
channel: this.VideoChannel.toFormattedJSON(), channel: this.VideoChannel.toFormattedJSON(),
@ -950,8 +979,10 @@ export class VideoModel extends Model<VideoModel> {
let resolutionLabel = videoFile.resolution + 'p' let resolutionLabel = videoFile.resolution + 'p'
return { return {
resolution: videoFile.resolution, resolution: {
resolutionLabel, id: videoFile.resolution,
label: resolutionLabel
},
magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs), magnetUri: this.generateMagnetUri(videoFile, baseUrlHttp, baseUrlWs),
size: videoFile.size, size: videoFile.size,
torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp), torrentUrl: this.getTorrentUrl(videoFile, baseUrlHttp),
@ -979,8 +1010,8 @@ export class VideoModel extends Model<VideoModel> {
let language let language
if (this.language) { if (this.language) {
language = { language = {
identifier: this.language + '', id: this.language + '',
name: this.getLanguageLabel() name: VideoModel.getLanguageLabel(this.language)
} }
} }
@ -988,7 +1019,7 @@ export class VideoModel extends Model<VideoModel> {
if (this.category) { if (this.category) {
category = { category = {
identifier: this.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) { if (this.licence) {
licence = { licence = {
identifier: this.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` 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 () { removeThumbnail () {
const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName())
return unlinkPromise(thumbnailPath) return unlinkPromise(thumbnailPath)

View File

@ -3,10 +3,14 @@ import { Avatar } from '../avatars/avatar.model'
import { VideoChannel } from './video-channel.model' import { VideoChannel } from './video-channel.model'
import { VideoPrivacy } from './video-privacy.enum' import { VideoPrivacy } from './video-privacy.enum'
export interface VideoConstant <T> {
id: number
label: string
}
export interface VideoFile { export interface VideoFile {
magnetUri: string magnetUri: string
resolution: number resolution: VideoConstant<number>
resolutionLabel: string
size: number // Bytes size: number // Bytes
torrentUrl: string torrentUrl: string
fileUrl: string fileUrl: string
@ -17,12 +21,9 @@ export interface Video {
uuid: string uuid: string
createdAt: Date | string createdAt: Date | string
updatedAt: Date | string updatedAt: Date | string
categoryLabel: string category: VideoConstant<number>
category: number licence: VideoConstant<number>
licenceLabel: string language: VideoConstant<number>
licence: number
languageLabel: string
language: number
description: string description: string
duration: number duration: number
isLocal: boolean isLocal: boolean
@ -45,8 +46,7 @@ export interface Video {
} }
export interface VideoDetails extends Video { export interface VideoDetails extends Video {
privacy: VideoPrivacy privacy: VideoConstant<VideoPrivacy>
privacyLabel: string
descriptionPath: string descriptionPath: string
support: string support: string
channel: VideoChannel channel: VideoChannel