]>
Commit | Line | Data |
---|---|---|
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' | |
6 | ||
7 | function getVideoWithAttributes (res: Response) { | |
8 | return res.locals.videoAPI || res.locals.videoAll || res.locals.onlyVideo | |
9 | } | |
10 | ||
11 | function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) { | |
12 | return isStreamingPlaylist(videoOrPlaylist) | |
13 | ? videoOrPlaylist.Video | |
14 | : videoOrPlaylist | |
15 | } | |
16 | ||
17 | function isPrivacyForFederation (privacy: VideoPrivacy) { | |
18 | const castedPrivacy = forceNumber(privacy) | |
19 | ||
20 | return castedPrivacy === VideoPrivacy.PUBLIC || | |
21 | (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true && castedPrivacy === VideoPrivacy.UNLISTED) | |
22 | } | |
23 | ||
24 | function isStateForFederation (state: VideoState) { | |
25 | const castedState = forceNumber(state) | |
26 | ||
27 | return castedState === VideoState.PUBLISHED || castedState === VideoState.WAITING_FOR_LIVE || castedState === VideoState.LIVE_ENDED | |
28 | } | |
29 | ||
30 | function getPrivaciesForFederation () { | |
31 | return (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true) | |
32 | ? [ { privacy: VideoPrivacy.PUBLIC }, { privacy: VideoPrivacy.UNLISTED } ] | |
33 | : [ { privacy: VideoPrivacy.PUBLIC } ] | |
34 | } | |
35 | ||
36 | function getExtFromMimetype (mimeTypes: { [id: string]: string | string[] }, mimeType: string) { | |
37 | const value = mimeTypes[mimeType] | |
38 | ||
39 | if (Array.isArray(value)) return value[0] | |
40 | ||
41 | return value | |
42 | } | |
43 | ||
44 | export { | |
45 | getVideoWithAttributes, | |
46 | extractVideo, | |
47 | getExtFromMimetype, | |
48 | isStateForFederation, | |
49 | isPrivacyForFederation, | |
50 | getPrivaciesForFederation | |
51 | } |