PeerTube/server/helpers/video.ts

52 lines
1.6 KiB
TypeScript
Raw Normal View History

import { Response } from 'express'
import { CONFIG } from '@server/initializers/config'
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models'
import { VideoPrivacy, VideoState } from '@shared/models'
import { forceNumber } from '@shared/core-utils'
2018-09-19 11:16:23 +02:00
2019-08-20 13:52:49 +02:00
function getVideoWithAttributes (res: Response) {
2021-06-11 14:09:33 +02:00
return res.locals.videoAPI || res.locals.videoAll || res.locals.onlyVideo
2019-08-20 13:52:49 +02:00
}
2020-04-23 09:32:53 +02:00
function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
return isStreamingPlaylist(videoOrPlaylist)
? videoOrPlaylist.Video
: videoOrPlaylist
}
function isPrivacyForFederation (privacy: VideoPrivacy) {
const castedPrivacy = forceNumber(privacy)
return castedPrivacy === VideoPrivacy.PUBLIC ||
(CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true && castedPrivacy === VideoPrivacy.UNLISTED)
}
2020-11-04 14:16:57 +01:00
function isStateForFederation (state: VideoState) {
const castedState = forceNumber(state)
2020-11-04 14:16:57 +01:00
return castedState === VideoState.PUBLISHED || castedState === VideoState.WAITING_FOR_LIVE || castedState === VideoState.LIVE_ENDED
}
function getPrivaciesForFederation () {
return (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true)
? [ { privacy: VideoPrivacy.PUBLIC }, { privacy: VideoPrivacy.UNLISTED } ]
: [ { privacy: VideoPrivacy.PUBLIC } ]
}
function getExtFromMimetype (mimeTypes: { [id: string]: string | string[] }, mimeType: string) {
const value = mimeTypes[mimeType]
if (Array.isArray(value)) return value[0]
return value
}
2018-09-19 11:16:23 +02:00
export {
2019-08-20 13:52:49 +02:00
getVideoWithAttributes,
extractVideo,
getExtFromMimetype,
2020-11-04 14:16:57 +01:00
isStateForFederation,
isPrivacyForFederation,
getPrivaciesForFederation
2018-09-19 11:16:23 +02:00
}