]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/helpers/video.ts
Do not support subscriptions to accounts
[github/Chocobozzz/PeerTube.git] / server / helpers / video.ts
... / ...
CommitLineData
1import { VideoModel } from '../models/video/video'
2import * as Bluebird from 'bluebird'
3import {
4 MVideoAccountLightBlacklistAllFiles,
5 MVideoFullLight,
6 MVideoIdThumbnail,
7 MVideoThumbnail,
8 MVideoWithRights,
9 MVideoImmutable
10} from '@server/typings/models'
11import { Response } from 'express'
12
13type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
14
15function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Bluebird<MVideoFullLight>
16function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Bluebird<MVideoImmutable>
17function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Bluebird<MVideoThumbnail>
18function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Bluebird<MVideoWithRights>
19function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Bluebird<MVideoIdThumbnail>
20function fetchVideo (
21 id: number | string,
22 fetchType: VideoFetchType,
23 userId?: number
24): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable>
25function fetchVideo (
26 id: number | string,
27 fetchType: VideoFetchType,
28 userId?: number
29): Bluebird<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {
30 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
31
32 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
33
34 if (fetchType === 'only-video-with-rights') return VideoModel.loadWithRights(id)
35
36 if (fetchType === 'only-video') return VideoModel.load(id)
37
38 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
39}
40
41type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
42
43function fetchVideoByUrl (url: string, fetchType: 'all'): Bluebird<MVideoAccountLightBlacklistAllFiles>
44function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Bluebird<MVideoImmutable>
45function fetchVideoByUrl (url: string, fetchType: 'only-video'): Bluebird<MVideoThumbnail>
46function fetchVideoByUrl (
47 url: string,
48 fetchType: VideoFetchByUrlType
49): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
50function fetchVideoByUrl (
51 url: string,
52 fetchType: VideoFetchByUrlType
53): Bluebird<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
54 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
55
56 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
57
58 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
59}
60
61function getVideoWithAttributes (res: Response) {
62 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights
63}
64
65export {
66 VideoFetchType,
67 VideoFetchByUrlType,
68 fetchVideo,
69 getVideoWithAttributes,
70 fetchVideoByUrl
71}