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