aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-11 09:57:19 +0200
committerChocobozzz <me@florianbigard.com>2021-06-11 09:57:19 +0200
commitca4b4b2e5590c1b37cff1fe1be7f797b93351229 (patch)
treee454de8be7b0dd6c28b08f27234fe6992ab9929c /server/lib
parent1d43c3a613c72d69f7360fee9e5bfe6f662d62f7 (diff)
downloadPeerTube-ca4b4b2e5590c1b37cff1fe1be7f797b93351229.tar.gz
PeerTube-ca4b4b2e5590c1b37cff1fe1be7f797b93351229.tar.zst
PeerTube-ca4b4b2e5590c1b37cff1fe1be7f797b93351229.zip
Fetch directly all video attributes for get API
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/model-loaders/video.ts14
1 files changed, 13 insertions, 1 deletions
diff --git a/server/lib/model-loaders/video.ts b/server/lib/model-loaders/video.ts
index 597c94395..07b373ed3 100644
--- a/server/lib/model-loaders/video.ts
+++ b/server/lib/model-loaders/video.ts
@@ -1,15 +1,18 @@
1import { VideoModel } from '@server/models/video/video' 1import { VideoModel } from '@server/models/video/video'
2import { 2import {
3 MVideoAccountLightBlacklistAllFiles, 3 MVideoAccountLightBlacklistAllFiles,
4 MVideoFormattableDetails,
4 MVideoFullLight, 5 MVideoFullLight,
5 MVideoIdThumbnail, 6 MVideoIdThumbnail,
6 MVideoImmutable, 7 MVideoImmutable,
7 MVideoThumbnail, 8 MVideoThumbnail,
8 MVideoWithRights 9 MVideoWithRights
9} from '@server/types/models' 10} from '@server/types/models'
11import { Hooks } from '../plugins/hooks'
10 12
11type VideoLoadType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' 13type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
12 14
15function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails>
13function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight> 16function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
14function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> 17function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
15function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail> 18function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
@@ -25,6 +28,15 @@ function loadVideo (
25 fetchType: VideoLoadType, 28 fetchType: VideoLoadType,
26 userId?: number 29 userId?: number
27): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> { 30): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {
31
32 if (fetchType === 'for-api') {
33 return Hooks.wrapPromiseFun(
34 VideoModel.loadForGetAPI,
35 { id, userId },
36 'filter:api.video.get.result'
37 )
38 }
39
28 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) 40 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
29 41
30 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id) 42 if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id)