]>
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 C |
7 | MVideoImmutable, |
8 | MVideoThumbnail, | |
9 | MVideoWithRights | |
10 | } from '@server/types/models' | |
ca4b4b2e | 11 | import { Hooks } from '../plugins/hooks' |
10363c74 | 12 | |
71d4af1e | 13 | type VideoLoadType = 'for-api' | 'all' | 'only-video' | '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> | |
71d4af1e | 19 | function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId> |
868fce62 | 20 | function loadVideo ( |
10363c74 | 21 | id: number | string, |
868fce62 | 22 | fetchType: VideoLoadType, |
10363c74 | 23 | userId?: number |
71d4af1e | 24 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> |
868fce62 | 25 | function loadVideo ( |
10363c74 | 26 | id: number | string, |
868fce62 | 27 | fetchType: VideoLoadType, |
10363c74 | 28 | userId?: number |
71d4af1e | 29 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> { |
ca4b4b2e C |
30 | |
31 | if (fetchType === 'for-api') { | |
32 | return Hooks.wrapPromiseFun( | |
33 | VideoModel.loadForGetAPI, | |
34 | { id, userId }, | |
35 | 'filter:api.video.get.result' | |
36 | ) | |
37 | } | |
38 | ||
10363c74 C |
39 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) |
40 | ||
41 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id) | |
42 | ||
10363c74 C |
43 | if (fetchType === 'only-video') return VideoModel.load(id) |
44 | ||
45 | if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) | |
46 | } | |
47 | ||
868fce62 | 48 | type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' |
10363c74 | 49 | |
868fce62 C |
50 | function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles> |
51 | function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | |
52 | function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail> | |
53 | function loadVideoByUrl ( | |
10363c74 | 54 | url: string, |
868fce62 | 55 | fetchType: VideoLoadByUrlType |
10363c74 | 56 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> |
868fce62 | 57 | function loadVideoByUrl ( |
10363c74 | 58 | url: string, |
868fce62 | 59 | fetchType: VideoLoadByUrlType |
10363c74 C |
60 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> { |
61 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) | |
62 | ||
63 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url) | |
64 | ||
65 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) | |
66 | } | |
67 | ||
68 | export { | |
868fce62 C |
69 | VideoLoadType, |
70 | VideoLoadByUrlType, | |
71 | ||
72 | loadVideo, | |
73 | loadVideoByUrl | |
10363c74 | 74 | } |