]>
Commit | Line | Data |
---|---|---|
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 | import { Hooks } from '../plugins/hooks' | |
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') { | |
31 | return Hooks.wrapPromiseFun( | |
32 | VideoModel.loadForGetAPI, | |
33 | { id, userId }, | |
34 | 'filter:api.video.get.result' | |
35 | ) | |
36 | } | |
37 | ||
38 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) | |
39 | ||
40 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id) | |
41 | ||
42 | if (fetchType === 'only-video') return VideoModel.load(id) | |
43 | ||
44 | if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) | |
45 | } | |
46 | ||
47 | type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' | |
48 | ||
49 | function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles> | |
50 | function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | |
51 | function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail> | |
52 | function loadVideoByUrl ( | |
53 | url: string, | |
54 | fetchType: VideoLoadByUrlType | |
55 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> | |
56 | function loadVideoByUrl ( | |
57 | url: string, | |
58 | fetchType: VideoLoadByUrlType | |
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 | ||
67 | export { | |
68 | VideoLoadType, | |
69 | VideoLoadByUrlType, | |
70 | ||
71 | loadVideo, | |
72 | loadVideoByUrl | |
73 | } |