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' | '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: 'id' | 'none', userId?: number): Promise<MVideoId>
22 fetchType: VideoLoadType,
24 ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable>
27 fetchType: VideoLoadType,
29 ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> {
31 if (fetchType === 'for-api') {
32 return Hooks.wrapPromiseFun(
33 VideoModel.loadForGetAPI,
35 'filter:api.video.get.result'
39 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
41 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
43 if (fetchType === 'only-video') return VideoModel.load(id)
45 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
48 type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
50 function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
51 function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
52 function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
53 function loadVideoByUrl (
55 fetchType: VideoLoadByUrlType
56 ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
57 function loadVideoByUrl (
59 fetchType: VideoLoadByUrlType
60 ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
61 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
63 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
65 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)