1 import { VideoModel } from '@server/models/video/video'
3 MVideoAccountLightBlacklistAllFiles,
4 MVideoFormattableDetails,
9 } from '@server/types/models'
10 import { Hooks } from '../plugins/hooks'
12 type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'id' | 'none' | 'only-immutable-attributes'
14 function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails>
15 function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
16 function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
17 function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
18 function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId>
21 fetchType: VideoLoadType,
23 ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable>
26 fetchType: VideoLoadType,
28 ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> {
30 if (fetchType === 'for-api') {
31 return Hooks.wrapPromiseFun(
32 VideoModel.loadForGetAPI,
34 'filter:api.video.get.result'
38 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
40 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
42 if (fetchType === 'only-video') return VideoModel.load(id)
44 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
47 type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
49 function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
50 function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
51 function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
52 function loadVideoByUrl (
54 fetchType: VideoLoadByUrlType
55 ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
56 function loadVideoByUrl (
58 fetchType: VideoLoadByUrlType
59 ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
60 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
62 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
64 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)