]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/model-loaders/video.ts
Add x-powered-by header
[github/Chocobozzz/PeerTube.git] / server / lib / model-loaders / video.ts
... / ...
CommitLineData
1import { VideoModel } from '@server/models/video/video'
2import {
3 MVideoAccountLightBlacklistAllFiles,
4 MVideoFormattableDetails,
5 MVideoFullLight,
6 MVideoId,
7 MVideoImmutable,
8 MVideoThumbnail
9} from '@server/types/models'
10
11type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'id' | 'none' | 'only-immutable-attributes'
12
13function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails>
14function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
15function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
16function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
17function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId>
18function loadVideo (
19 id: number | string,
20 fetchType: VideoLoadType,
21 userId?: number
22): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable>
23function loadVideo (
24 id: number | string,
25 fetchType: VideoLoadType,
26 userId?: number
27): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> {
28
29 if (fetchType === 'for-api') return VideoModel.loadForGetAPI({ id, userId })
30
31 if (fetchType === 'all') return VideoModel.loadFull(id, undefined, userId)
32
33 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
34
35 if (fetchType === 'only-video') return VideoModel.load(id)
36
37 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
38}
39
40type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
41
42function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
43function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
44function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
45function loadVideoByUrl (
46 url: string,
47 fetchType: VideoLoadByUrlType
48): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
49function loadVideoByUrl (
50 url: string,
51 fetchType: VideoLoadByUrlType
52): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
53 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
54
55 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
56
57 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
58}
59
60export {
61 VideoLoadType,
62 VideoLoadByUrlType,
63
64 loadVideo,
65 loadVideoByUrl
66}