]>
Commit | Line | Data |
---|---|---|
10363c74 C |
1 | import { VideoModel } from '@server/models/video/video' |
2 | import { | |
3 | MVideoAccountLightBlacklistAllFiles, | |
ca4b4b2e | 4 | MVideoFormattableDetails, |
10363c74 C |
5 | MVideoFullLight, |
6 | MVideoIdThumbnail, | |
7 | MVideoImmutable, | |
8 | MVideoThumbnail, | |
9 | MVideoWithRights | |
10 | } from '@server/types/models' | |
ca4b4b2e | 11 | import { Hooks } from '../plugins/hooks' |
10363c74 | 12 | |
ca4b4b2e | 13 | type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' |
10363c74 | 14 | |
ca4b4b2e | 15 | function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails> |
868fce62 C |
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 ( | |
10363c74 | 22 | id: number | string, |
868fce62 | 23 | fetchType: VideoLoadType, |
10363c74 C |
24 | userId?: number |
25 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> | |
868fce62 | 26 | function loadVideo ( |
10363c74 | 27 | id: number | string, |
868fce62 | 28 | fetchType: VideoLoadType, |
10363c74 C |
29 | userId?: number |
30 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> { | |
ca4b4b2e C |
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 | ||
10363c74 C |
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 | ||
868fce62 | 51 | type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' |
10363c74 | 52 | |
868fce62 C |
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 ( | |
10363c74 | 57 | url: string, |
868fce62 | 58 | fetchType: VideoLoadByUrlType |
10363c74 | 59 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> |
868fce62 | 60 | function loadVideoByUrl ( |
10363c74 | 61 | url: string, |
868fce62 | 62 | fetchType: VideoLoadByUrlType |
10363c74 C |
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 { | |
868fce62 C |
72 | VideoLoadType, |
73 | VideoLoadByUrlType, | |
74 | ||
75 | loadVideo, | |
76 | loadVideoByUrl | |
10363c74 | 77 | } |