]>
Commit | Line | Data |
---|---|---|
30bc55c8 C |
1 | import { Response } from 'express' |
2 | import { CONFIG } from '@server/initializers/config' | |
10363c74 | 3 | import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models' |
77d7e851 | 4 | import { VideoPrivacy, VideoState } from '@shared/models' |
4638cd71 | 5 | import { forceNumber } from '@shared/core-utils' |
4157cdb1 | 6 | |
0283eaac | 7 | function getVideoWithAttributes (res: Response) { |
71d4af1e | 8 | return res.locals.videoAPI || res.locals.videoAll || res.locals.onlyVideo |
0283eaac C |
9 | } |
10 | ||
8dc8a34e C |
11 | function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) { |
12 | return isStreamingPlaylist(videoOrPlaylist) | |
13 | ? videoOrPlaylist.Video | |
14 | : videoOrPlaylist | |
15 | } | |
16 | ||
3092e9bb | 17 | function isPrivacyForFederation (privacy: VideoPrivacy) { |
4638cd71 | 18 | const castedPrivacy = forceNumber(privacy) |
3092e9bb LB |
19 | |
20 | return castedPrivacy === VideoPrivacy.PUBLIC || | |
21 | (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true && castedPrivacy === VideoPrivacy.UNLISTED) | |
22 | } | |
23 | ||
68e70a74 | 24 | function isStateForFederation (state: VideoState) { |
4638cd71 | 25 | const castedState = forceNumber(state) |
68e70a74 C |
26 | |
27 | return castedState === VideoState.PUBLISHED || castedState === VideoState.WAITING_FOR_LIVE || castedState === VideoState.LIVE_ENDED | |
68e70a74 C |
28 | } |
29 | ||
3092e9bb LB |
30 | function getPrivaciesForFederation () { |
31 | return (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true) | |
32 | ? [ { privacy: VideoPrivacy.PUBLIC }, { privacy: VideoPrivacy.UNLISTED } ] | |
33 | : [ { privacy: VideoPrivacy.PUBLIC } ] | |
34 | } | |
35 | ||
30bc55c8 C |
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 | ||
4157cdb1 | 44 | export { |
0283eaac | 45 | getVideoWithAttributes, |
3092e9bb | 46 | extractVideo, |
30bc55c8 | 47 | getExtFromMimetype, |
68e70a74 | 48 | isStateForFederation, |
3092e9bb LB |
49 | isPrivacyForFederation, |
50 | getPrivaciesForFederation | |
4157cdb1 | 51 | } |