]>
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' |
ca4b4b2e | 10 | import { Hooks } from '../plugins/hooks' |
10363c74 | 11 | |
71d4af1e | 12 | type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'id' | 'none' | 'only-immutable-attributes' |
10363c74 | 13 | |
ca4b4b2e | 14 | function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails> |
868fce62 C |
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> | |
71d4af1e | 18 | function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId> |
868fce62 | 19 | function loadVideo ( |
10363c74 | 20 | id: number | string, |
868fce62 | 21 | fetchType: VideoLoadType, |
10363c74 | 22 | userId?: number |
71d4af1e | 23 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> |
868fce62 | 24 | function loadVideo ( |
10363c74 | 25 | id: number | string, |
868fce62 | 26 | fetchType: VideoLoadType, |
10363c74 | 27 | userId?: number |
71d4af1e | 28 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> { |
ca4b4b2e C |
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 | ||
10363c74 C |
38 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) |
39 | ||
40 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id) | |
41 | ||
10363c74 C |
42 | if (fetchType === 'only-video') return VideoModel.load(id) |
43 | ||
44 | if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) | |
45 | } | |
46 | ||
868fce62 | 47 | type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' |
10363c74 | 48 | |
868fce62 C |
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 ( | |
10363c74 | 53 | url: string, |
868fce62 | 54 | fetchType: VideoLoadByUrlType |
10363c74 | 55 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> |
868fce62 | 56 | function loadVideoByUrl ( |
10363c74 | 57 | url: string, |
868fce62 | 58 | fetchType: VideoLoadByUrlType |
10363c74 C |
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 { | |
868fce62 C |
68 | VideoLoadType, |
69 | VideoLoadByUrlType, | |
70 | ||
71 | loadVideo, | |
72 | loadVideoByUrl | |
10363c74 | 73 | } |