From 7c3a6636fdd9b905345996d825c249a18add8a2c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 11 Jun 2021 14:36:07 +0200 Subject: Move get* video methods to formatter --- server/controllers/feeds.ts | 3 +- .../models/video/formatter/video-format-utils.ts | 57 +++++++++++++++++----- server/models/video/video.ts | 20 -------- 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index 865f5c2a1..435b12193 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts @@ -1,5 +1,6 @@ import * as express from 'express' 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 { buildNSFWFilter } from '../helpers/express-utils' import { CONFIG } from '../initializers/config' @@ -286,7 +287,7 @@ function addVideosToFeed (feed, videos: VideoModel[]) { if (video.category) { categories.push({ value: video.category, - label: VideoModel.getCategoryLabel(video.category) + label: getCategoryLabel(video.category) }) } diff --git a/server/models/video/formatter/video-format-utils.ts b/server/models/video/formatter/video-format-utils.ts index 5ddbf74da..8880c0450 100644 --- a/server/models/video/formatter/video-format-utils.ts +++ b/server/models/video/formatter/video-format-utils.ts @@ -5,7 +5,15 @@ import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../../s import { Video, VideoDetails } from '../../../../shared/models/videos' import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model' 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 { getLocalVideoCommentsActivityPubUrl, getLocalVideoDislikesActivityPubUrl, @@ -21,7 +29,6 @@ import { MVideoFormattableDetails } from '../../../types/models' import { MVideoFileRedundanciesOpt } from '../../../types/models/video/video-file' -import { VideoModel } from '../video' import { VideoCaptionModel } from '../video-caption' export type VideoFormattingJSONOptions = { @@ -43,19 +50,19 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor name: video.name, category: { id: video.category, - label: VideoModel.getCategoryLabel(video.category) + label: getCategoryLabel(video.category) }, licence: { id: video.licence, - label: VideoModel.getLicenceLabel(video.licence) + label: getLicenceLabel(video.licence) }, language: { id: video.language, - label: VideoModel.getLanguageLabel(video.language) + label: getLanguageLabel(video.language) }, privacy: { id: video.privacy, - label: VideoModel.getPrivacyLabel(video.privacy) + label: getPrivacyLabel(video.privacy) }, nsfw: video.nsfw, @@ -93,7 +100,7 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor if (options.additionalAttributes.state === true) { videoObject.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, state: { id: video.state, - label: VideoModel.getStateLabel(video.state) + label: getStateLabel(video.state) }, trackerUrls: video.getTrackerUrls(), @@ -283,7 +290,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject { if (video.language) { 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) { 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) { 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' } +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 { videoModelToFormattedJSON, videoModelToFormattedDetailsJSON, videoFilesModelToFormattedJSON, videoModelToActivityPubObject, - getActivityStreamDuration + getActivityStreamDuration, + + getCategoryLabel, + getLicenceLabel, + getLanguageLabel, + getPrivacyLabel, + getStateLabel } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 2d8b7b653..f3782fb43 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1556,26 +1556,6 @@ export class VideoModel extends Model>> { } } - 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 () { return !!this.VideoBlacklist } -- cgit v1.2.3