]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/video.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / server / helpers / video.ts
CommitLineData
4157cdb1 1import { VideoModel } from '../models/video/video'
453e83ea 2import * as Bluebird from 'bluebird'
0283eaac
C
3import {
4 MVideoAccountLightBlacklistAllFiles,
5 MVideoFullLight,
6 MVideoIdThumbnail,
7 MVideoThumbnail,
8 MVideoWithRights
9} from '@server/typings/models'
453e83ea 10import { Response } from 'express'
4157cdb1 11
09209296 12type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none'
4157cdb1 13
453e83ea
C
14function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Bluebird<MVideoFullLight>
15function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Bluebird<MVideoThumbnail>
16function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Bluebird<MVideoWithRights>
17function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Bluebird<MVideoIdThumbnail>
18function fetchVideo (
19 id: number | string,
20 fetchType: VideoFetchType,
21 userId?: number
22): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail>
23function 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
37type VideoFetchByUrlType = 'all' | 'only-video'
453e83ea 38
0283eaac 39function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird<MVideoAccountLightBlacklistAllFiles>
453e83ea 40function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird<MVideoThumbnail>
0283eaac
C
41function fetchVideoByUrl (url: string, fetchType: VideoFetchByUrlType): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail>
42function 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
453e83ea
C
48function getVideo (res: Response) {
49 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights || res.locals.videoId
50}
51
0283eaac
C
52function getVideoWithAttributes (res: Response) {
53 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights
54}
55
4157cdb1
C
56export {
57 VideoFetchType,
58 VideoFetchByUrlType,
59 fetchVideo,
453e83ea 60 getVideo,
0283eaac 61 getVideoWithAttributes,
4157cdb1
C
62 fetchVideoByUrl
63}