From ca4b4b2e5590c1b37cff1fe1be7f797b93351229 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 11 Jun 2021 09:57:19 +0200 Subject: Fetch directly all video attributes for get API --- server/lib/model-loaders/video.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'server/lib') 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 @@ import { VideoModel } from '@server/models/video/video' import { MVideoAccountLightBlacklistAllFiles, + MVideoFormattableDetails, MVideoFullLight, MVideoIdThumbnail, MVideoImmutable, MVideoThumbnail, MVideoWithRights } from '@server/types/models' +import { Hooks } from '../plugins/hooks' -type VideoLoadType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' +type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' +function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise @@ -25,6 +28,15 @@ function loadVideo ( fetchType: VideoLoadType, userId?: number ): Promise { + + if (fetchType === 'for-api') { + return Hooks.wrapPromiseFun( + VideoModel.loadForGetAPI, + { id, userId }, + 'filter:api.video.get.result' + ) + } + if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id) -- cgit v1.2.3