diff options
Diffstat (limited to 'server/helpers/video.ts')
-rw-r--r-- | server/helpers/video.ts | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/server/helpers/video.ts b/server/helpers/video.ts index c90fe06c7..26a72ac5c 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts | |||
@@ -1,8 +1,24 @@ | |||
1 | import { VideoModel } from '../models/video/video' | 1 | import { VideoModel } from '../models/video/video' |
2 | import * as Bluebird from 'bluebird' | ||
3 | import { MVideoAccountAllFiles, MVideoFullLight, MVideoThumbnail, MVideoWithRights, MVideoIdThumbnail } from '@server/typings/models' | ||
4 | import { Response } from 'express' | ||
2 | 5 | ||
3 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 6 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' |
4 | 7 | ||
5 | function fetchVideo (id: number | string, fetchType: VideoFetchType, userId?: number) { | 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> { | ||
6 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) | 22 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) |
7 | 23 | ||
8 | if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) | 24 | if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) |
@@ -13,15 +29,24 @@ function fetchVideo (id: number | string, fetchType: VideoFetchType, userId?: nu | |||
13 | } | 29 | } |
14 | 30 | ||
15 | type VideoFetchByUrlType = 'all' | 'only-video' | 31 | type VideoFetchByUrlType = 'all' | 'only-video' |
16 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType) { | 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> { | ||
17 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) | 37 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) |
18 | 38 | ||
19 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) | 39 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) |
20 | } | 40 | } |
21 | 41 | ||
42 | function getVideo (res: Response) { | ||
43 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights || res.locals.videoId | ||
44 | } | ||
45 | |||
22 | export { | 46 | export { |
23 | VideoFetchType, | 47 | VideoFetchType, |
24 | VideoFetchByUrlType, | 48 | VideoFetchByUrlType, |
25 | fetchVideo, | 49 | fetchVideo, |
50 | getVideo, | ||
26 | fetchVideoByUrl | 51 | fetchVideoByUrl |
27 | } | 52 | } |