]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/model-loaders/video.ts
Merge branch 'release/4.2.0' into develop
[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'
10import { Hooks } from '../plugins/hooks'
11
12type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'id' | 'none' | 'only-immutable-attributes'
13
14function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails>
15function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
16function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
17function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
18function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId>
19function loadVideo (
20 id: number | string,
21 fetchType: VideoLoadType,
22 userId?: number
23): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable>
24function loadVideo (
25 id: number | string,
26 fetchType: VideoLoadType,
27 userId?: number
28): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> {
29
30 if (fetchType === 'for-api') {
31 return Hooks.wrapPromiseFun(
32 VideoModel.loadForGetAPI,
33 { id, userId },
34 'filter:api.video.get.result'
35 )
36 }
37
38 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
39
40 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)
41
42 if (fetchType === 'only-video') return VideoModel.load(id)
43
44 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
45}
46
47type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
48
49function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
50function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
51function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
52function loadVideoByUrl (
53 url: string,
54 fetchType: VideoLoadByUrlType
55): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
56function loadVideoByUrl (
57 url: string,
58 fetchType: VideoLoadByUrlType
59): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
60 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
61
62 if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url)
63
64 if (fetchType === 'only-video') return VideoModel.loadByUrl(url)
65}
66
67export {
68 VideoLoadType,
69 VideoLoadByUrlType,
70
71 loadVideo,
72 loadVideoByUrl
73}