aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/feeds.ts3
-rw-r--r--server/models/video/formatter/video-format-utils.ts57
-rw-r--r--server/models/video/video.ts20
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as Feed from 'pfeed' 2import * as Feed from 'pfeed'
3import { getCategoryLabel } from '@server/models/video/formatter/video-format-utils'
3import { VideoFilter } from '../../shared/models/videos/video-query.type' 4import { VideoFilter } from '../../shared/models/videos/video-query.type'
4import { buildNSFWFilter } from '../helpers/express-utils' 5import { buildNSFWFilter } from '../helpers/express-utils'
5import { CONFIG } from '../initializers/config' 6import { CONFIG } from '../initializers/config'
@@ -286,7 +287,7 @@ function addVideosToFeed (feed, videos: VideoModel[]) {
286 if (video.category) { 287 if (video.category) {
287 categories.push({ 288 categories.push({
288 value: video.category, 289 value: video.category,
289 label: VideoModel.getCategoryLabel(video.category) 290 label: getCategoryLabel(video.category)
290 }) 291 })
291 } 292 }
292 293
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
5import { Video, VideoDetails } from '../../../../shared/models/videos' 5import { Video, VideoDetails } from '../../../../shared/models/videos'
6import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model' 6import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model'
7import { isArray } from '../../../helpers/custom-validators/misc' 7import { isArray } from '../../../helpers/custom-validators/misc'
8import { MIMETYPES, WEBSERVER } from '../../../initializers/constants' 8import {
9 MIMETYPES,
10 VIDEO_CATEGORIES,
11 VIDEO_LANGUAGES,
12 VIDEO_LICENCES,
13 VIDEO_PRIVACIES,
14 VIDEO_STATES,
15 WEBSERVER
16} from '../../../initializers/constants'
9import { 17import {
10 getLocalVideoCommentsActivityPubUrl, 18 getLocalVideoCommentsActivityPubUrl,
11 getLocalVideoDislikesActivityPubUrl, 19 getLocalVideoDislikesActivityPubUrl,
@@ -21,7 +29,6 @@ import {
21 MVideoFormattableDetails 29 MVideoFormattableDetails
22} from '../../../types/models' 30} from '../../../types/models'
23import { MVideoFileRedundanciesOpt } from '../../../types/models/video/video-file' 31import { MVideoFileRedundanciesOpt } from '../../../types/models/video/video-file'
24import { VideoModel } from '../video'
25import { VideoCaptionModel } from '../video-caption' 32import { VideoCaptionModel } from '../video-caption'
26 33
27export type VideoFormattingJSONOptions = { 34export type VideoFormattingJSONOptions = {
@@ -43,19 +50,19 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor
43 name: video.name, 50 name: video.name,
44 category: { 51 category: {
45 id: video.category, 52 id: video.category,
46 label: VideoModel.getCategoryLabel(video.category) 53 label: getCategoryLabel(video.category)
47 }, 54 },
48 licence: { 55 licence: {
49 id: video.licence, 56 id: video.licence,
50 label: VideoModel.getLicenceLabel(video.licence) 57 label: getLicenceLabel(video.licence)
51 }, 58 },
52 language: { 59 language: {
53 id: video.language, 60 id: video.language,
54 label: VideoModel.getLanguageLabel(video.language) 61 label: getLanguageLabel(video.language)
55 }, 62 },
56 privacy: { 63 privacy: {
57 id: video.privacy, 64 id: video.privacy,
58 label: VideoModel.getPrivacyLabel(video.privacy) 65 label: getPrivacyLabel(video.privacy)
59 }, 66 },
60 nsfw: video.nsfw, 67 nsfw: video.nsfw,
61 68
@@ -93,7 +100,7 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor
93 if (options.additionalAttributes.state === true) { 100 if (options.additionalAttributes.state === true) {
94 videoObject.state = { 101 videoObject.state = {
95 id: video.state, 102 id: video.state,
96 label: VideoModel.getStateLabel(video.state) 103 label: getStateLabel(video.state)
97 } 104 }
98 } 105 }
99 106
@@ -140,7 +147,7 @@ function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): Vid
140 waitTranscoding: video.waitTranscoding, 147 waitTranscoding: video.waitTranscoding,
141 state: { 148 state: {
142 id: video.state, 149 id: video.state,
143 label: VideoModel.getStateLabel(video.state) 150 label: getStateLabel(video.state)
144 }, 151 },
145 152
146 trackerUrls: video.getTrackerUrls(), 153 trackerUrls: video.getTrackerUrls(),
@@ -283,7 +290,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
283 if (video.language) { 290 if (video.language) {
284 language = { 291 language = {
285 identifier: video.language, 292 identifier: video.language,
286 name: VideoModel.getLanguageLabel(video.language) 293 name: getLanguageLabel(video.language)
287 } 294 }
288 } 295 }
289 296
@@ -291,7 +298,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
291 if (video.category) { 298 if (video.category) {
292 category = { 299 category = {
293 identifier: video.category + '', 300 identifier: video.category + '',
294 name: VideoModel.getCategoryLabel(video.category) 301 name: getCategoryLabel(video.category)
295 } 302 }
296 } 303 }
297 304
@@ -299,7 +306,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
299 if (video.licence) { 306 if (video.licence) {
300 licence = { 307 licence = {
301 identifier: video.licence + '', 308 identifier: video.licence + '',
302 name: VideoModel.getLicenceLabel(video.licence) 309 name: getLicenceLabel(video.licence)
303 } 310 }
304 } 311 }
305 312
@@ -425,10 +432,36 @@ function getActivityStreamDuration (duration: number) {
425 return 'PT' + duration + 'S' 432 return 'PT' + duration + 'S'
426} 433}
427 434
435function getCategoryLabel (id: number) {
436 return VIDEO_CATEGORIES[id] || 'Misc'
437}
438
439function getLicenceLabel (id: number) {
440 return VIDEO_LICENCES[id] || 'Unknown'
441}
442
443function getLanguageLabel (id: string) {
444 return VIDEO_LANGUAGES[id] || 'Unknown'
445}
446
447function getPrivacyLabel (id: number) {
448 return VIDEO_PRIVACIES[id] || 'Unknown'
449}
450
451function getStateLabel (id: number) {
452 return VIDEO_STATES[id] || 'Unknown'
453}
454
428export { 455export {
429 videoModelToFormattedJSON, 456 videoModelToFormattedJSON,
430 videoModelToFormattedDetailsJSON, 457 videoModelToFormattedDetailsJSON,
431 videoFilesModelToFormattedJSON, 458 videoFilesModelToFormattedJSON,
432 videoModelToActivityPubObject, 459 videoModelToActivityPubObject,
433 getActivityStreamDuration 460 getActivityStreamDuration,
461
462 getCategoryLabel,
463 getLicenceLabel,
464 getLanguageLabel,
465 getPrivacyLabel,
466 getStateLabel
434} 467}
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<Partial<AttributesOnly<VideoModel>>> {
1556 } 1556 }
1557 } 1557 }
1558 1558
1559 static getCategoryLabel (id: number) {
1560 return VIDEO_CATEGORIES[id] || 'Misc'
1561 }
1562
1563 static getLicenceLabel (id: number) {
1564 return VIDEO_LICENCES[id] || 'Unknown'
1565 }
1566
1567 static getLanguageLabel (id: string) {
1568 return VIDEO_LANGUAGES[id] || 'Unknown'
1569 }
1570
1571 static getPrivacyLabel (id: number) {
1572 return VIDEO_PRIVACIES[id] || 'Unknown'
1573 }
1574
1575 static getStateLabel (id: number) {
1576 return VIDEO_STATES[id] || 'Unknown'
1577 }
1578
1579 isBlacklisted () { 1559 isBlacklisted () {
1580 return !!this.VideoBlacklist 1560 return !!this.VideoBlacklist
1581 } 1561 }