X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fvideo.ts;h=f5f645d3eac1997614c177f00c5a64c215f38ef0;hb=ab18fadfd1104ff2fab1b7e90915426a0c707b7f;hp=6f76cbdfc755a23f14f882600b86a7366e93747d;hpb=8dc8a34ee8428e7657414115d1c137592efa174d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/video.ts b/server/helpers/video.ts index 6f76cbdfc..f5f645d3e 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts @@ -1,107 +1,50 @@ -import { VideoModel } from '../models/video/video' -import * as Bluebird from 'bluebird' -import { - isStreamingPlaylist, - MStreamingPlaylistVideo, - MVideo, - MVideoAccountLightBlacklistAllFiles, - MVideoFile, - MVideoFullLight, - MVideoIdThumbnail, - 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' +import { CONFIG } from '@server/initializers/config' +import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models' +import { VideoPrivacy, VideoState } from '@shared/models' -type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' - -function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Bluebird -function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Bluebird -function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Bluebird -function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Bluebird -function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Bluebird -function fetchVideo ( - id: number | string, - fetchType: VideoFetchType, - userId?: number -): Bluebird -function fetchVideo ( - id: number | string, - fetchType: VideoFetchType, - userId?: number -): Bluebird { - if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) - - if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id) - - if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) - - if (fetchType === 'only-video') return VideoModel.load(id) +function getVideoWithAttributes (res: Response) { + return res.locals.videoAPI || res.locals.videoAll || res.locals.onlyVideo +} - if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) +function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) { + return isStreamingPlaylist(videoOrPlaylist) + ? videoOrPlaylist.Video + : videoOrPlaylist } -type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' +function isPrivacyForFederation (privacy: VideoPrivacy) { + const castedPrivacy = parseInt(privacy + '', 10) -function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird -function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Bluebird -function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird -function fetchVideoByUrl ( - url: string, - fetchType: VideoFetchByUrlType -): Bluebird -function fetchVideoByUrl ( - url: string, - fetchType: VideoFetchByUrlType -): Bluebird { - if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) + return castedPrivacy === VideoPrivacy.PUBLIC || + (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true && castedPrivacy === VideoPrivacy.UNLISTED) +} - if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url) +function isStateForFederation (state: VideoState) { + const castedState = parseInt(state + '', 10) - if (fetchType === 'only-video') return VideoModel.loadByUrl(url) + return castedState === VideoState.PUBLISHED || castedState === VideoState.WAITING_FOR_LIVE || castedState === VideoState.LIVE_ENDED } -function getVideoWithAttributes (res: Response) { - return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights +function getPrivaciesForFederation () { + return (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true) + ? [ { privacy: VideoPrivacy.PUBLIC }, { privacy: VideoPrivacy.UNLISTED } ] + : [ { privacy: VideoPrivacy.PUBLIC } ] } -function addOptimizeOrMergeAudioJob (video: MVideo, videoFile: MVideoFile) { - let dataInput: VideoTranscodingPayload +function getExtFromMimetype (mimeTypes: { [id: string]: string | string[] }, mimeType: string) { + const value = mimeTypes[mimeType] - if (videoFile.isAudio()) { - dataInput = { - type: 'merge-audio' as 'merge-audio', - resolution: DEFAULT_AUDIO_RESOLUTION, - videoUUID: video.uuid, - isNewVideo: true - } - } else { - dataInput = { - type: 'optimize' as 'optimize', - videoUUID: video.uuid, - isNewVideo: true - } - } - - return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput }) -} + if (Array.isArray(value)) return value[0] -function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) { - return isStreamingPlaylist(videoOrPlaylist) - ? videoOrPlaylist.Video - : videoOrPlaylist + return value } export { - VideoFetchType, - VideoFetchByUrlType, - fetchVideo, getVideoWithAttributes, - fetchVideoByUrl, - addOptimizeOrMergeAudioJob, - extractVideo + extractVideo, + getExtFromMimetype, + isStateForFederation, + isPrivacyForFederation, + getPrivaciesForFederation }