From 453e83ea5d81d203ba34bc43cd5c2c750ba40568 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Aug 2019 11:53:26 +0200 Subject: Stronger model typings --- server/helpers/video.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'server/helpers/video.ts') 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 @@ import { VideoModel } from '../models/video/video' +import * as Bluebird from 'bluebird' +import { MVideoAccountAllFiles, MVideoFullLight, MVideoThumbnail, MVideoWithRights, MVideoIdThumbnail } from '@server/typings/models' +import { Response } from 'express' type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' -function fetchVideo (id: number | string, fetchType: VideoFetchType, userId?: number) { +function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Bluebird +function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Bluebird +function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Bluebird +function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Bluebird +function fetchVideo ( + id: number | string, + fetchType: VideoFetchType, + userId?: number +): Bluebird +function fetchVideo ( + id: number | string, + fetchType: VideoFetchType, + userId?: number +): Bluebird { if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id) @@ -13,15 +29,24 @@ function fetchVideo (id: number | string, fetchType: VideoFetchType, userId?: nu } type VideoFetchByUrlType = 'all' | 'only-video' -function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType) { + +function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird +function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird +function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird | Bluebird +function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird | Bluebird { if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) if (fetchType === 'only-video') return VideoModel.loadByUrl(url) } +function getVideo (res: Response) { + return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights || res.locals.videoId +} + export { VideoFetchType, VideoFetchByUrlType, fetchVideo, + getVideo, fetchVideoByUrl } -- cgit v1.2.3