1 import { VideoModel } from '../models/video/video'
2 import * as Bluebird from 'bluebird'
4 MVideoAccountLightBlacklistAllFiles,
10 } from '@server/typings/models'
11 import { Response } from 'express'
13 type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
15 function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Bluebird<MVideoFullLight>
16 function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Bluebird<MVideoImmutable>
17 function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Bluebird<MVideoThumbnail>
18 function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Bluebird<MVideoWithRights>
19 function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Bluebird<MVideoIdThumbnail>
22 fetchType: VideoFetchType,
24 ): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable>
27 fetchType: VideoFetchType,
29 ): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {
30 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
32 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
34 if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id)
36 if (fetchType === 'only-video') return VideoModel.load(id)
38 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
41 type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
43 function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird<MVideoAccountLightBlacklistAllFiles>
44 function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Bluebird<MVideoImmutable>
45 function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird<MVideoThumbnail>
46 function fetchVideoByUrl (
48 fetchType: VideoFetchByUrlType
49 ): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
50 function fetchVideoByUrl (
52 fetchType: VideoFetchByUrlType
53 ): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
54 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
56 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
58 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
61 function getVideoWithAttributes (res: Response) {
62 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights
69 getVideoWithAttributes,