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