diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-11 09:57:19 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-11 09:57:19 +0200 |
commit | ca4b4b2e5590c1b37cff1fe1be7f797b93351229 (patch) | |
tree | e454de8be7b0dd6c28b08f27234fe6992ab9929c /server/lib | |
parent | 1d43c3a613c72d69f7360fee9e5bfe6f662d62f7 (diff) | |
download | PeerTube-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.ts | 14 |
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 @@ | |||
1 | import { VideoModel } from '@server/models/video/video' | 1 | import { VideoModel } from '@server/models/video/video' |
2 | import { | 2 | import { |
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' |
11 | import { Hooks } from '../plugins/hooks' | ||
10 | 12 | ||
11 | type VideoLoadType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' | 13 | type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' |
12 | 14 | ||
15 | function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails> | ||
13 | function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight> | 16 | function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight> |
14 | function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | 17 | function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> |
15 | function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail> | 18 | function 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) |