1 import { VideoModel } from '@server/models/video/video'
3 MVideoAccountLightBlacklistAllFiles,
4 MVideoFormattableDetails,
9 } from '@server/types/models'
11 type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'id' | 'none' | 'only-immutable-attributes'
13 function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails>
14 function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
15 function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
16 function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
17 function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId>
20 fetchType: VideoLoadType,
22 ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable>
25 fetchType: VideoLoadType,
27 ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> {
29 if (fetchType === 'for-api') return VideoModel.loadForGetAPI({ id, userId })
31 if (fetchType === 'all') return VideoModel.loadFull(id, undefined, userId)
33 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
35 if (fetchType === 'only-video') return VideoModel.load(id)
37 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
40 type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
42 function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
43 function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
44 function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
45 function loadVideoByUrl (
47 fetchType: VideoLoadByUrlType
48 ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
49 function loadVideoByUrl (
51 fetchType: VideoLoadByUrlType
52 ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
53 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
55 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
57 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)