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