diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-22 10:43:11 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-22 10:43:11 +0200 |
commit | 5c5e587307a27e173333789b5b5167d35f468b01 (patch) | |
tree | 94e3721caf2e11d38fd5f4112c0fc98da89ac535 /server/helpers/video.ts | |
parent | 1b42d73f44811eec1b7ddd72dd0d640a57c3376c (diff) | |
parent | b5fecbf44192144d1ca27c23a0b53922de288c10 (diff) | |
download | PeerTube-5c5e587307a27e173333789b5b5167d35f468b01.tar.gz PeerTube-5c5e587307a27e173333789b5b5167d35f468b01.tar.zst PeerTube-5c5e587307a27e173333789b5b5167d35f468b01.zip |
Merge branch 'feature/strong-model-types' into develop
Diffstat (limited to 'server/helpers/video.ts')
-rw-r--r-- | server/helpers/video.ts | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/server/helpers/video.ts b/server/helpers/video.ts index c90fe06c7..d066e2b1f 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts | |||
@@ -1,8 +1,30 @@ | |||
1 | import { VideoModel } from '../models/video/video' | 1 | import { VideoModel } from '../models/video/video' |
2 | import * as Bluebird from 'bluebird' | ||
3 | import { | ||
4 | MVideoAccountLightBlacklistAllFiles, | ||
5 | MVideoFullLight, | ||
6 | MVideoIdThumbnail, | ||
7 | MVideoThumbnail, | ||
8 | MVideoWithRights | ||
9 | } from '@server/typings/models' | ||
10 | import { Response } from 'express' | ||
2 | 11 | ||
3 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 12 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' |
4 | 13 | ||
5 | function fetchVideo (id: number | string, fetchType: VideoFetchType, userId?: number) { | 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> { | ||
6 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) | 28 | if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) |
7 | 29 | ||
8 | if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) | 30 | if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) |
@@ -13,15 +35,29 @@ function fetchVideo (id: number | string, fetchType: VideoFetchType, userId?: nu | |||
13 | } | 35 | } |
14 | 36 | ||
15 | type VideoFetchByUrlType = 'all' | 'only-video' | 37 | type VideoFetchByUrlType = 'all' | 'only-video' |
16 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType) { | 38 | |
39 | function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird<MVideoAccountLightBlacklistAllFiles> | ||
40 | function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird<MVideoThumbnail> | ||
41 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> | ||
42 | function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> { | ||
17 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) | 43 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) |
18 | 44 | ||
19 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) | 45 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) |
20 | } | 46 | } |
21 | 47 | ||
48 | function getVideo (res: Response) { | ||
49 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights || res.locals.videoId | ||
50 | } | ||
51 | |||
52 | function getVideoWithAttributes (res: Response) { | ||
53 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights | ||
54 | } | ||
55 | |||
22 | export { | 56 | export { |
23 | VideoFetchType, | 57 | VideoFetchType, |
24 | VideoFetchByUrlType, | 58 | VideoFetchByUrlType, |
25 | fetchVideo, | 59 | fetchVideo, |
60 | getVideo, | ||
61 | getVideoWithAttributes, | ||
26 | fetchVideoByUrl | 62 | fetchVideoByUrl |
27 | } | 63 | } |