1 import { Response } from 'express'
2 import { CONFIG } from '@server/initializers/config'
3 import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models'
4 import { VideoPrivacy, VideoState } from '@shared/models'
5 import { forceNumber } from '@shared/core-utils'
7 function getVideoWithAttributes (res: Response) {
8 return res.locals.videoAPI || res.locals.videoAll || res.locals.onlyVideo
11 function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
12 return isStreamingPlaylist(videoOrPlaylist)
13 ? videoOrPlaylist.Video
17 function isPrivacyForFederation (privacy: VideoPrivacy) {
18 const castedPrivacy = forceNumber(privacy)
20 return castedPrivacy === VideoPrivacy.PUBLIC ||
21 (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true && castedPrivacy === VideoPrivacy.UNLISTED)
24 function isStateForFederation (state: VideoState) {
25 const castedState = forceNumber(state)
27 return castedState === VideoState.PUBLISHED || castedState === VideoState.WAITING_FOR_LIVE || castedState === VideoState.LIVE_ENDED
30 function getPrivaciesForFederation () {
31 return (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true)
32 ? [ { privacy: VideoPrivacy.PUBLIC }, { privacy: VideoPrivacy.UNLISTED } ]
33 : [ { privacy: VideoPrivacy.PUBLIC } ]
36 function getExtFromMimetype (mimeTypes: { [id: string]: string | string[] }, mimeType: string) {
37 const value = mimeTypes[mimeType]
39 if (Array.isArray(value)) return value[0]
45 getVideoWithAttributes,
49 isPrivacyForFederation,
50 getPrivaciesForFederation