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