]>
Commit | Line | Data |
---|---|---|
1 | import { VideoModel } from '@server/models/video/video' | |
2 | import { | |
3 | MVideoAccountLightBlacklistAllFiles, | |
4 | MVideoFormattableDetails, | |
5 | MVideoFullLight, | |
6 | MVideoIdThumbnail, | |
7 | MVideoImmutable, | |
8 | MVideoThumbnail, | |
9 | MVideoWithRights | |
10 | } from '@server/types/models' | |
11 | import { Hooks } from '../plugins/hooks' | |
12 | ||
13 | type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' | |
14 | ||
15 | function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails> | |
16 | function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight> | |
17 | function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | |
18 | function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail> | |
19 | function loadVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights> | |
20 | function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail> | |
21 | function loadVideo ( | |
22 | id: number | string, | |
23 | fetchType: VideoLoadType, | |
24 | userId?: number | |
25 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> | |
26 | function loadVideo ( | |
27 | id: number | string, | |
28 | fetchType: VideoLoadType, | |
29 | userId?: number | |
30 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> { | |
31 | ||
32 | if (fetchType === 'for-api') { | |
33 | return Hooks.wrapPromiseFun( | |
34 | VideoModel.loadForGetAPI, | |
35 | { id, userId }, | |
36 | 'filter:api.video.get.result' | |
37 | ) | |
38 | } | |
39 | ||
40 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) | |
41 | ||
42 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id) | |
43 | ||
44 | if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) | |
45 | ||
46 | if (fetchType === 'only-video') return VideoModel.load(id) | |
47 | ||
48 | if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) | |
49 | } | |
50 | ||
51 | type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' | |
52 | ||
53 | function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles> | |
54 | function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | |
55 | function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail> | |
56 | function loadVideoByUrl ( | |
57 | url: string, | |
58 | fetchType: VideoLoadByUrlType | |
59 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> | |
60 | function loadVideoByUrl ( | |
61 | url: string, | |
62 | fetchType: VideoLoadByUrlType | |
63 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> { | |
64 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) | |
65 | ||
66 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url) | |
67 | ||
68 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) | |
69 | } | |
70 | ||
71 | export { | |
72 | VideoLoadType, | |
73 | VideoLoadByUrlType, | |
74 | ||
75 | loadVideo, | |
76 | loadVideoByUrl | |
77 | } |