1 import { VideoModel } from '@server/models/video/video'
3 MVideoAccountLightBlacklistAllFiles,
4 MVideoFormattableDetails,
10 } from '@server/types/models'
11 import { Hooks } from '../plugins/hooks'
13 type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
15 function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails>
16 function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
17 function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
18 function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
19 function loadVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights>
20 function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail>
23 fetchType: VideoLoadType,
25 ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable>
28 fetchType: VideoLoadType,
30 ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {
32 if (fetchType === 'for-api') {
33 return Hooks.wrapPromiseFun(
34 VideoModel.loadForGetAPI,
36 'filter:api.video.get.result'
40 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
42 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
44 if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id)
46 if (fetchType === 'only-video') return VideoModel.load(id)
48 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
51 type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
53 function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
54 function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
55 function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
56 function loadVideoByUrl (
58 fetchType: VideoLoadByUrlType
59 ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
60 function loadVideoByUrl (
62 fetchType: VideoLoadByUrlType
63 ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
64 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
66 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
68 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)