2020-08-10 08:25:29 -04:00
|
|
|
import { Response } from 'express'
|
|
|
|
import { CONFIG } from '@server/initializers/config'
|
2021-06-03 11:33:44 -04:00
|
|
|
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models'
|
2021-01-21 10:57:21 -05:00
|
|
|
import { VideoPrivacy, VideoState } from '@shared/models'
|
2018-09-19 05:16:23 -04:00
|
|
|
|
2019-08-20 07:52:49 -04:00
|
|
|
function getVideoWithAttributes (res: Response) {
|
2021-06-11 08:09:33 -04:00
|
|
|
return res.locals.videoAPI || res.locals.videoAll || res.locals.onlyVideo
|
2019-08-20 07:52:49 -04:00
|
|
|
}
|
|
|
|
|
2020-04-23 03:32:53 -04:00
|
|
|
function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
|
|
|
|
return isStreamingPlaylist(videoOrPlaylist)
|
|
|
|
? videoOrPlaylist.Video
|
|
|
|
: videoOrPlaylist
|
|
|
|
}
|
|
|
|
|
2020-06-03 03:42:07 -04:00
|
|
|
function isPrivacyForFederation (privacy: VideoPrivacy) {
|
|
|
|
const castedPrivacy = parseInt(privacy + '', 10)
|
|
|
|
|
|
|
|
return castedPrivacy === VideoPrivacy.PUBLIC ||
|
|
|
|
(CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true && castedPrivacy === VideoPrivacy.UNLISTED)
|
|
|
|
}
|
|
|
|
|
2020-11-04 08:16:57 -05:00
|
|
|
function isStateForFederation (state: VideoState) {
|
|
|
|
const castedState = parseInt(state + '', 10)
|
|
|
|
|
|
|
|
return castedState === VideoState.PUBLISHED || castedState === VideoState.WAITING_FOR_LIVE || castedState === VideoState.LIVE_ENDED
|
|
|
|
}
|
|
|
|
|
2020-06-03 03:42:07 -04:00
|
|
|
function getPrivaciesForFederation () {
|
|
|
|
return (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true)
|
|
|
|
? [ { privacy: VideoPrivacy.PUBLIC }, { privacy: VideoPrivacy.UNLISTED } ]
|
|
|
|
: [ { privacy: VideoPrivacy.PUBLIC } ]
|
|
|
|
}
|
|
|
|
|
2020-08-10 08:25:29 -04:00
|
|
|
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 05:16:23 -04:00
|
|
|
export {
|
2019-08-20 07:52:49 -04:00
|
|
|
getVideoWithAttributes,
|
2020-06-03 03:42:07 -04:00
|
|
|
extractVideo,
|
2020-08-10 08:25:29 -04:00
|
|
|
getExtFromMimetype,
|
2020-11-04 08:16:57 -05:00
|
|
|
isStateForFederation,
|
2020-06-03 03:42:07 -04:00
|
|
|
isPrivacyForFederation,
|
|
|
|
getPrivaciesForFederation
|
2018-09-19 05:16:23 -04:00
|
|
|
}
|