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