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'
6 function getVideoWithAttributes (res: Response) {
7 return res.locals.videoAPI || res.locals.videoAll || res.locals.onlyVideo
10 function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
11 return isStreamingPlaylist(videoOrPlaylist)
12 ? videoOrPlaylist.Video
16 function isPrivacyForFederation (privacy: VideoPrivacy) {
17 const castedPrivacy = parseInt(privacy + '', 10)
19 return castedPrivacy === VideoPrivacy.PUBLIC ||
20 (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true && castedPrivacy === VideoPrivacy.UNLISTED)
23 function isStateForFederation (state: VideoState) {
24 const castedState = parseInt(state + '', 10)
26 return castedState === VideoState.PUBLISHED || castedState === VideoState.WAITING_FOR_LIVE || castedState === VideoState.LIVE_ENDED
29 function getPrivaciesForFederation () {
30 return (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true)
31 ? [ { privacy: VideoPrivacy.PUBLIC }, { privacy: VideoPrivacy.UNLISTED } ]
32 : [ { privacy: VideoPrivacy.PUBLIC } ]
35 function getExtFromMimetype (mimeTypes: { [id: string]: string | string[] }, mimeType: string) {
36 const value = mimeTypes[mimeType]
38 if (Array.isArray(value)) return value[0]
44 getVideoWithAttributes,
48 isPrivacyForFederation,
49 getPrivaciesForFederation