1 import { VideoModel } from '../models/video/video'
2 import * as Bluebird from 'bluebird'
4 MVideoAccountLightBlacklistAllFiles,
9 } from '@server/typings/models'
10 import { Response } from 'express'
12 type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none'
14 function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Bluebird<MVideoFullLight>
15 function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Bluebird<MVideoThumbnail>
16 function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Bluebird<MVideoWithRights>
17 function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Bluebird<MVideoIdThumbnail>
20 fetchType: VideoFetchType,
22 ): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail>
25 fetchType: VideoFetchType,
27 ): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail> {
28 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
30 if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id)
32 if (fetchType === 'only-video') return VideoModel.load(id)
34 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
37 type VideoFetchByUrlType = 'all' | 'only-video'
39 function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird<MVideoAccountLightBlacklistAllFiles>
40 function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird<MVideoThumbnail>
41 function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail>
42 function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> {
43 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
45 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
48 function getVideoWithAttributes (res: Response) {
49 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights
56 getVideoWithAttributes,