Move get* video methods to formatter
This commit is contained in:
parent
fd6a74a835
commit
7c3a6636fd
3 changed files with 47 additions and 33 deletions
|
@ -1,5 +1,6 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import * as Feed from 'pfeed'
|
import * as Feed from 'pfeed'
|
||||||
|
import { getCategoryLabel } from '@server/models/video/formatter/video-format-utils'
|
||||||
import { VideoFilter } from '../../shared/models/videos/video-query.type'
|
import { VideoFilter } from '../../shared/models/videos/video-query.type'
|
||||||
import { buildNSFWFilter } from '../helpers/express-utils'
|
import { buildNSFWFilter } from '../helpers/express-utils'
|
||||||
import { CONFIG } from '../initializers/config'
|
import { CONFIG } from '../initializers/config'
|
||||||
|
@ -286,7 +287,7 @@ function addVideosToFeed (feed, videos: VideoModel[]) {
|
||||||
if (video.category) {
|
if (video.category) {
|
||||||
categories.push({
|
categories.push({
|
||||||
value: video.category,
|
value: video.category,
|
||||||
label: VideoModel.getCategoryLabel(video.category)
|
label: getCategoryLabel(video.category)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,15 @@ import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../../s
|
||||||
import { Video, VideoDetails } from '../../../../shared/models/videos'
|
import { Video, VideoDetails } from '../../../../shared/models/videos'
|
||||||
import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model'
|
import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model'
|
||||||
import { isArray } from '../../../helpers/custom-validators/misc'
|
import { isArray } from '../../../helpers/custom-validators/misc'
|
||||||
import { MIMETYPES, WEBSERVER } from '../../../initializers/constants'
|
import {
|
||||||
|
MIMETYPES,
|
||||||
|
VIDEO_CATEGORIES,
|
||||||
|
VIDEO_LANGUAGES,
|
||||||
|
VIDEO_LICENCES,
|
||||||
|
VIDEO_PRIVACIES,
|
||||||
|
VIDEO_STATES,
|
||||||
|
WEBSERVER
|
||||||
|
} from '../../../initializers/constants'
|
||||||
import {
|
import {
|
||||||
getLocalVideoCommentsActivityPubUrl,
|
getLocalVideoCommentsActivityPubUrl,
|
||||||
getLocalVideoDislikesActivityPubUrl,
|
getLocalVideoDislikesActivityPubUrl,
|
||||||
|
@ -21,7 +29,6 @@ import {
|
||||||
MVideoFormattableDetails
|
MVideoFormattableDetails
|
||||||
} from '../../../types/models'
|
} from '../../../types/models'
|
||||||
import { MVideoFileRedundanciesOpt } from '../../../types/models/video/video-file'
|
import { MVideoFileRedundanciesOpt } from '../../../types/models/video/video-file'
|
||||||
import { VideoModel } from '../video'
|
|
||||||
import { VideoCaptionModel } from '../video-caption'
|
import { VideoCaptionModel } from '../video-caption'
|
||||||
|
|
||||||
export type VideoFormattingJSONOptions = {
|
export type VideoFormattingJSONOptions = {
|
||||||
|
@ -43,19 +50,19 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor
|
||||||
name: video.name,
|
name: video.name,
|
||||||
category: {
|
category: {
|
||||||
id: video.category,
|
id: video.category,
|
||||||
label: VideoModel.getCategoryLabel(video.category)
|
label: getCategoryLabel(video.category)
|
||||||
},
|
},
|
||||||
licence: {
|
licence: {
|
||||||
id: video.licence,
|
id: video.licence,
|
||||||
label: VideoModel.getLicenceLabel(video.licence)
|
label: getLicenceLabel(video.licence)
|
||||||
},
|
},
|
||||||
language: {
|
language: {
|
||||||
id: video.language,
|
id: video.language,
|
||||||
label: VideoModel.getLanguageLabel(video.language)
|
label: getLanguageLabel(video.language)
|
||||||
},
|
},
|
||||||
privacy: {
|
privacy: {
|
||||||
id: video.privacy,
|
id: video.privacy,
|
||||||
label: VideoModel.getPrivacyLabel(video.privacy)
|
label: getPrivacyLabel(video.privacy)
|
||||||
},
|
},
|
||||||
nsfw: video.nsfw,
|
nsfw: video.nsfw,
|
||||||
|
|
||||||
|
@ -93,7 +100,7 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor
|
||||||
if (options.additionalAttributes.state === true) {
|
if (options.additionalAttributes.state === true) {
|
||||||
videoObject.state = {
|
videoObject.state = {
|
||||||
id: video.state,
|
id: video.state,
|
||||||
label: VideoModel.getStateLabel(video.state)
|
label: getStateLabel(video.state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +147,7 @@ function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): Vid
|
||||||
waitTranscoding: video.waitTranscoding,
|
waitTranscoding: video.waitTranscoding,
|
||||||
state: {
|
state: {
|
||||||
id: video.state,
|
id: video.state,
|
||||||
label: VideoModel.getStateLabel(video.state)
|
label: getStateLabel(video.state)
|
||||||
},
|
},
|
||||||
|
|
||||||
trackerUrls: video.getTrackerUrls(),
|
trackerUrls: video.getTrackerUrls(),
|
||||||
|
@ -283,7 +290,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
|
||||||
if (video.language) {
|
if (video.language) {
|
||||||
language = {
|
language = {
|
||||||
identifier: video.language,
|
identifier: video.language,
|
||||||
name: VideoModel.getLanguageLabel(video.language)
|
name: getLanguageLabel(video.language)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +298,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
|
||||||
if (video.category) {
|
if (video.category) {
|
||||||
category = {
|
category = {
|
||||||
identifier: video.category + '',
|
identifier: video.category + '',
|
||||||
name: VideoModel.getCategoryLabel(video.category)
|
name: getCategoryLabel(video.category)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +306,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
|
||||||
if (video.licence) {
|
if (video.licence) {
|
||||||
licence = {
|
licence = {
|
||||||
identifier: video.licence + '',
|
identifier: video.licence + '',
|
||||||
name: VideoModel.getLicenceLabel(video.licence)
|
name: getLicenceLabel(video.licence)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,10 +432,36 @@ function getActivityStreamDuration (duration: number) {
|
||||||
return 'PT' + duration + 'S'
|
return 'PT' + duration + 'S'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCategoryLabel (id: number) {
|
||||||
|
return VIDEO_CATEGORIES[id] || 'Misc'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLicenceLabel (id: number) {
|
||||||
|
return VIDEO_LICENCES[id] || 'Unknown'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLanguageLabel (id: string) {
|
||||||
|
return VIDEO_LANGUAGES[id] || 'Unknown'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPrivacyLabel (id: number) {
|
||||||
|
return VIDEO_PRIVACIES[id] || 'Unknown'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStateLabel (id: number) {
|
||||||
|
return VIDEO_STATES[id] || 'Unknown'
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
videoModelToFormattedJSON,
|
videoModelToFormattedJSON,
|
||||||
videoModelToFormattedDetailsJSON,
|
videoModelToFormattedDetailsJSON,
|
||||||
videoFilesModelToFormattedJSON,
|
videoFilesModelToFormattedJSON,
|
||||||
videoModelToActivityPubObject,
|
videoModelToActivityPubObject,
|
||||||
getActivityStreamDuration
|
getActivityStreamDuration,
|
||||||
|
|
||||||
|
getCategoryLabel,
|
||||||
|
getLicenceLabel,
|
||||||
|
getLanguageLabel,
|
||||||
|
getPrivacyLabel,
|
||||||
|
getStateLabel
|
||||||
}
|
}
|
||||||
|
|
|
@ -1556,26 +1556,6 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getCategoryLabel (id: number) {
|
|
||||||
return VIDEO_CATEGORIES[id] || 'Misc'
|
|
||||||
}
|
|
||||||
|
|
||||||
static getLicenceLabel (id: number) {
|
|
||||||
return VIDEO_LICENCES[id] || 'Unknown'
|
|
||||||
}
|
|
||||||
|
|
||||||
static getLanguageLabel (id: string) {
|
|
||||||
return VIDEO_LANGUAGES[id] || 'Unknown'
|
|
||||||
}
|
|
||||||
|
|
||||||
static getPrivacyLabel (id: number) {
|
|
||||||
return VIDEO_PRIVACIES[id] || 'Unknown'
|
|
||||||
}
|
|
||||||
|
|
||||||
static getStateLabel (id: number) {
|
|
||||||
return VIDEO_STATES[id] || 'Unknown'
|
|
||||||
}
|
|
||||||
|
|
||||||
isBlacklisted () {
|
isBlacklisted () {
|
||||||
return !!this.VideoBlacklist
|
return !!this.VideoBlacklist
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue