ActivityPub-federated video streaming platform using P2P directly in your web browser
Move get* video methods to formatter
Chocobozzz7c3a6636fdd9
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.tsindex 865f5c2a12..435b12193a 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.tsindex 5ddbf74dac..8880c0450f 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 '../../../../simport { 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?: VideoForname: 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?: VideoForif (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): VidwaitTranscoding: 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.tsindex 2d8b7b653a..f3782fb434 100644--- a/server/models/video/video.ts+++ b/server/models/video/video.ts@@ -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 () {return !!this.VideoBlacklist}