ActivityPub-federated video streaming platform using P2P directly in your web browser
Fetch directly all video attributes for get API
Chocobozzzca4b4b2e5590
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.tsindex 35992e9936..5fdb7d5bc5 100644--- a/server/controllers/api/videos/index.ts+++ b/server/controllers/api/videos/index.ts@@ -100,7 +100,7 @@ videosRouter.get('/:id/metadata/:videoFileId',videosRouter.get('/:id',openapiOperationDoc({ operationId: 'getVideo' }),optionalAuthenticate,- asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),+ asyncMiddleware(videosCustomGetValidator('for-api')),asyncMiddleware(checkVideoFollowConstraints),asyncMiddleware(getVideo))@@ -142,14 +142,7 @@ function listVideoPrivacies (_req: express.Request, res: express.Response) {}async function getVideo (_req: express.Request, res: express.Response) {- // We need more attributes- const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null-- const video = await Hooks.wrapPromiseFun(- VideoModel.loadForGetAPI,- { id: _req.params.id, userId },- 'filter:api.video.get.result'- )+ const video = res.locals.videoAPIif (video.isOutdated()) {JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })diff --git a/server/helpers/video.ts b/server/helpers/video.tsindex d3445bed5e..c2e15a7055 100644--- a/server/helpers/video.ts+++ b/server/helpers/video.ts@@ -4,7 +4,7 @@ import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/tyimport { VideoPrivacy, VideoState } from '@shared/models'function getVideoWithAttributes (res: Response) {- return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights+ return res.locals.videoAPI || res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights}function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {diff --git a/server/lib/model-loaders/video.ts b/server/lib/model-loaders/video.tsindex 597c94395b..07b373ed39 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<MVideoFormattableDetails>function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>@@ -25,6 +28,15 @@ function loadVideo (fetchType: VideoLoadType,userId?: number): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {++ 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)diff --git a/server/middlewares/validators/shared/videos.ts b/server/middlewares/validators/shared/videos.tsindex 3134f623d9..1a22d65138 100644--- a/server/middlewares/validators/shared/videos.ts+++ b/server/middlewares/validators/shared/videos.ts@@ -6,6 +6,7 @@ import {MUser,MUserAccountId,MVideoAccountLight,+ MVideoFormattableDetails,MVideoFullLight,MVideoIdThumbnail,MVideoImmutable,@@ -29,6 +30,10 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi}switch (fetchType) {+ case 'for-api':+ res.locals.videoAPI = video as MVideoFormattableDetails+ break+case 'all':res.locals.videoAll = video as MVideoFullLightbreakdiff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.tsindex 7f278c9f65..a707fd0869 100644--- a/server/middlewares/validators/videos/videos.ts+++ b/server/middlewares/validators/videos/videos.ts@@ -258,7 +258,7 @@ async function checkVideoFollowConstraints (req: express.Request, res: express.R}const videosCustomGetValidator = (- fetchType: 'all' | 'only-video' | 'only-video-with-rights' | 'only-immutable-attributes',+ fetchType: 'for-api' | 'all' | 'only-video' | 'only-video-with-rights' | 'only-immutable-attributes',authenticateInQuery = false) => {return [diff --git a/server/models/video/video.ts b/server/models/video/video.tsindex 9d56eb13c9..00fbb18f69 100644--- a/server/models/video/video.ts+++ b/server/models/video/video.ts@@ -1472,13 +1472,13 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {static loadForGetAPI (parameters: {id: number | string- t?: Transaction+ transaction?: TransactionuserId?: number}): Promise<MVideoDetails> {- const { id, t, userId } = parameters+ const { id, transaction, userId } = parametersconst queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize)- return queryBuilder.queryVideos({ id, transaction: t, forGetAPI: true, userId })+ return queryBuilder.queryVideos({ id, transaction, forGetAPI: true, userId })}static async getStats () {diff --git a/server/typings/express/index.d.ts b/server/typings/express/index.d.tsindex cbbf40a786..00ff689438 100644--- a/server/typings/express/index.d.ts+++ b/server/typings/express/index.d.ts@@ -10,6 +10,7 @@ import {MStreamingPlaylist,MVideoChangeOwnershipFull,MVideoFile,+ MVideoFormattableDetails,MVideoImmutable,MVideoLive,MVideoPlaylistFull,@@ -101,6 +102,7 @@ declare module 'express' {locals: {docUrl?: string+ videoAPI?: MVideoFormattableDetailsvideoAll?: MVideoFullLightonlyImmutableVideo?: MVideoImmutableonlyVideo?: MVideoThumbnail