]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/model-loaders/video.ts
Optimize join build
[github/Chocobozzz/PeerTube.git] / server / lib / model-loaders / video.ts
CommitLineData
10363c74
C
1import { VideoModel } from '@server/models/video/video'
2import {
3 MVideoAccountLightBlacklistAllFiles,
ca4b4b2e 4 MVideoFormattableDetails,
10363c74
C
5 MVideoFullLight,
6 MVideoIdThumbnail,
7 MVideoImmutable,
8 MVideoThumbnail,
9 MVideoWithRights
10} from '@server/types/models'
ca4b4b2e 11import { Hooks } from '../plugins/hooks'
10363c74 12
ca4b4b2e 13type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
10363c74 14
ca4b4b2e 15function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails>
868fce62
C
16function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
17function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
18function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
19function loadVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights>
20function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail>
21function loadVideo (
10363c74 22 id: number | string,
868fce62 23 fetchType: VideoLoadType,
10363c74
C
24 userId?: number
25): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable>
868fce62 26function loadVideo (
10363c74 27 id: number | string,
868fce62 28 fetchType: VideoLoadType,
10363c74
C
29 userId?: number
30): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {
ca4b4b2e
C
31
32 if (fetchType === 'for-api') {
33 return Hooks.wrapPromiseFun(
34 VideoModel.loadForGetAPI,
35 { id, userId },
36 'filter:api.video.get.result'
37 )
38 }
39
10363c74
C
40 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
41
42 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
43
44 if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id)
45
46 if (fetchType === 'only-video') return VideoModel.load(id)
47
48 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
49}
50
868fce62 51type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
10363c74 52
868fce62
C
53function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
54function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
55function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
56function loadVideoByUrl (
10363c74 57 url: string,
868fce62 58 fetchType: VideoLoadByUrlType
10363c74 59): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
868fce62 60function loadVideoByUrl (
10363c74 61 url: string,
868fce62 62 fetchType: VideoLoadByUrlType
10363c74
C
63): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
64 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
65
66 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
67
68 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
69}
70
71export {
868fce62
C
72 VideoLoadType,
73 VideoLoadByUrlType,
74
75 loadVideo,
76 loadVideoByUrl
10363c74 77}