diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-11 14:36:07 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-11 14:36:07 +0200 |
commit | 7c3a6636fdd9b905345996d825c249a18add8a2c (patch) | |
tree | 2392a297d579345837fc2ed9f225693888ee1bd4 /server/models/video/formatter | |
parent | fd6a74a83594bfb59e28bf9cae71a39884ebcc2f (diff) | |
download | PeerTube-7c3a6636fdd9b905345996d825c249a18add8a2c.tar.gz PeerTube-7c3a6636fdd9b905345996d825c249a18add8a2c.tar.zst PeerTube-7c3a6636fdd9b905345996d825c249a18add8a2c.zip |
Move get* video methods to formatter
Diffstat (limited to 'server/models/video/formatter')
-rw-r--r-- | server/models/video/formatter/video-format-utils.ts | 57 |
1 files changed, 45 insertions, 12 deletions
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 | |||
5 | import { Video, VideoDetails } from '../../../../shared/models/videos' | 5 | import { Video, VideoDetails } from '../../../../shared/models/videos' |
6 | import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model' | 6 | import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model' |
7 | import { isArray } from '../../../helpers/custom-validators/misc' | 7 | import { isArray } from '../../../helpers/custom-validators/misc' |
8 | import { MIMETYPES, WEBSERVER } from '../../../initializers/constants' | 8 | import { |
9 | MIMETYPES, | ||
10 | VIDEO_CATEGORIES, | ||
11 | VIDEO_LANGUAGES, | ||
12 | VIDEO_LICENCES, | ||
13 | VIDEO_PRIVACIES, | ||
14 | VIDEO_STATES, | ||
15 | WEBSERVER | ||
16 | } from '../../../initializers/constants' | ||
9 | import { | 17 | import { |
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' |
23 | import { MVideoFileRedundanciesOpt } from '../../../types/models/video/video-file' | 31 | import { MVideoFileRedundanciesOpt } from '../../../types/models/video/video-file' |
24 | import { VideoModel } from '../video' | ||
25 | import { VideoCaptionModel } from '../video-caption' | 32 | import { VideoCaptionModel } from '../video-caption' |
26 | 33 | ||
27 | export type VideoFormattingJSONOptions = { | 34 | export 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 | ||
435 | function getCategoryLabel (id: number) { | ||
436 | return VIDEO_CATEGORIES[id] || 'Misc' | ||
437 | } | ||
438 | |||
439 | function getLicenceLabel (id: number) { | ||
440 | return VIDEO_LICENCES[id] || 'Unknown' | ||
441 | } | ||
442 | |||
443 | function getLanguageLabel (id: string) { | ||
444 | return VIDEO_LANGUAGES[id] || 'Unknown' | ||
445 | } | ||
446 | |||
447 | function getPrivacyLabel (id: number) { | ||
448 | return VIDEO_PRIVACIES[id] || 'Unknown' | ||
449 | } | ||
450 | |||
451 | function getStateLabel (id: number) { | ||
452 | return VIDEO_STATES[id] || 'Unknown' | ||
453 | } | ||
454 | |||
428 | export { | 455 | export { |
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 | } |