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