]>
Commit | Line | Data |
---|---|---|
4157cdb1 | 1 | import { VideoModel } from '../models/video/video' |
453e83ea C |
2 | import * as Bluebird from 'bluebird' |
3 | import { MVideoAccountAllFiles, MVideoFullLight, MVideoThumbnail, MVideoWithRights, MVideoIdThumbnail } from '@server/typings/models' | |
4 | import { Response } from 'express' | |
4157cdb1 | 5 | |
09209296 | 6 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' |
4157cdb1 | 7 | |
453e83ea C |
8 | function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Bluebird<MVideoFullLight> |
9 | function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Bluebird<MVideoThumbnail> | |
10 | function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Bluebird<MVideoWithRights> | |
11 | function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Bluebird<MVideoIdThumbnail> | |
12 | function fetchVideo ( | |
13 | id: number | string, | |
14 | fetchType: VideoFetchType, | |
15 | userId?: number | |
16 | ): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail> | |
17 | function fetchVideo ( | |
18 | id: number | string, | |
19 | fetchType: VideoFetchType, | |
20 | userId?: number | |
21 | ): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail> { | |
6e46de09 | 22 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) |
4157cdb1 | 23 | |
09209296 C |
24 | if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) |
25 | ||
4157cdb1 C |
26 | if (fetchType === 'only-video') return VideoModel.load(id) |
27 | ||
28 | if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) | |
29 | } | |
30 | ||
31 | type VideoFetchByUrlType = 'all' | 'only-video' | |
453e83ea C |
32 | |
33 | function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird<MVideoAccountAllFiles> | |
34 | function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird<MVideoThumbnail> | |
35 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountAllFiles> | Bluebird<MVideoThumbnail> | |
36 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountAllFiles> | Bluebird<MVideoThumbnail> { | |
4157cdb1 C |
37 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) |
38 | ||
39 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) | |
40 | } | |
41 | ||
453e83ea C |
42 | function getVideo (res: Response) { |
43 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights || res.locals.videoId | |
44 | } | |
45 | ||
4157cdb1 C |
46 | export { |
47 | VideoFetchType, | |
48 | VideoFetchByUrlType, | |
49 | fetchVideo, | |
453e83ea | 50 | getVideo, |
4157cdb1 C |
51 | fetchVideoByUrl |
52 | } |