X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fvideo.ts;h=488b4da17149118b559664fed007fe5a0760e7b4;hb=7673c1f6a4f7d672c68b53904b391b6c87bd88f7;hp=6f76cbdfc755a23f14f882600b86a7366e93747d;hpb=8dc8a34ee8428e7657414115d1c137592efa174d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/video.ts b/server/helpers/video.ts index 6f76cbdfc..488b4da17 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts @@ -1,5 +1,8 @@ -import { VideoModel } from '../models/video/video' import * as Bluebird from 'bluebird' +import { Response } from 'express' +import { CONFIG } from '@server/initializers/config' +import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants' +import { JobQueue } from '@server/lib/job-queue' import { isStreamingPlaylist, MStreamingPlaylistVideo, @@ -11,11 +14,9 @@ import { MVideoImmutable, MVideoThumbnail, MVideoWithRights -} from '@server/typings/models' -import { Response } from 'express' -import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants' -import { JobQueue } from '@server/lib/job-queue' -import { VideoTranscodingPayload } from '@shared/models' +} from '@server/types/models' +import { VideoPrivacy, VideoTranscodingPayload } from '@shared/models' +import { VideoModel } from '../models/video/video' type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' @@ -96,6 +97,27 @@ function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) { : videoOrPlaylist } +function isPrivacyForFederation (privacy: VideoPrivacy) { + const castedPrivacy = parseInt(privacy + '', 10) + + return castedPrivacy === VideoPrivacy.PUBLIC || + (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true && castedPrivacy === VideoPrivacy.UNLISTED) +} + +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 +} + export { VideoFetchType, VideoFetchByUrlType, @@ -103,5 +125,8 @@ export { getVideoWithAttributes, fetchVideoByUrl, addOptimizeOrMergeAudioJob, - extractVideo + extractVideo, + getExtFromMimetype, + isPrivacyForFederation, + getPrivaciesForFederation }