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