]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/model-loaders/video.ts
7aaf00e895df79a3d95a52784214c3c222907198
[github/Chocobozzz/PeerTube.git] / server / lib / model-loaders / video.ts
1 import { VideoModel } from '@server/models/video/video'
2 import {
3 MVideoAccountLightBlacklistAllFiles,
4 MVideoFullLight,
5 MVideoIdThumbnail,
6 MVideoImmutable,
7 MVideoThumbnail,
8 MVideoWithRights
9 } from '@server/types/models'
10
11 type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
12
13 function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
14 function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
15 function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
16 function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights>
17 function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail>
18 function fetchVideo (
19 id: number | string,
20 fetchType: VideoFetchType,
21 userId?: number
22 ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable>
23 function fetchVideo (
24 id: number | string,
25 fetchType: VideoFetchType,
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
39 type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
40
41 function fetchVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
42 function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
43 function fetchVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
44 function fetchVideoByUrl (
45 url: string,
46 fetchType: VideoFetchByUrlType
47 ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
48 function fetchVideoByUrl (
49 url: string,
50 fetchType: VideoFetchByUrlType
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
59 export {
60 VideoFetchType,
61 VideoFetchByUrlType,
62 fetchVideo,
63 fetchVideoByUrl
64 }