aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/api/videos/index.ts11
-rw-r--r--server/helpers/video.ts2
-rw-r--r--server/lib/model-loaders/video.ts14
-rw-r--r--server/middlewares/validators/shared/videos.ts5
-rw-r--r--server/middlewares/validators/videos/videos.ts2
-rw-r--r--server/models/video/video.ts6
-rw-r--r--server/typings/express/index.d.ts2
7 files changed, 27 insertions, 15 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 35992e993..5fdb7d5bc 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -100,7 +100,7 @@ videosRouter.get('/:id/metadata/:videoFileId',
100videosRouter.get('/:id', 100videosRouter.get('/:id',
101 openapiOperationDoc({ operationId: 'getVideo' }), 101 openapiOperationDoc({ operationId: 'getVideo' }),
102 optionalAuthenticate, 102 optionalAuthenticate,
103 asyncMiddleware(videosCustomGetValidator('only-video-with-rights')), 103 asyncMiddleware(videosCustomGetValidator('for-api')),
104 asyncMiddleware(checkVideoFollowConstraints), 104 asyncMiddleware(checkVideoFollowConstraints),
105 asyncMiddleware(getVideo) 105 asyncMiddleware(getVideo)
106) 106)
@@ -142,14 +142,7 @@ function listVideoPrivacies (_req: express.Request, res: express.Response) {
142} 142}
143 143
144async function getVideo (_req: express.Request, res: express.Response) { 144async function getVideo (_req: express.Request, res: express.Response) {
145 // We need more attributes 145 const video = res.locals.videoAPI
146 const userId: number = res.locals.oauth ? res.locals.oauth.token.User.id : null
147
148 const video = await Hooks.wrapPromiseFun(
149 VideoModel.loadForGetAPI,
150 { id: _req.params.id, userId },
151 'filter:api.video.get.result'
152 )
153 146
154 if (video.isOutdated()) { 147 if (video.isOutdated()) {
155 JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } }) 148 JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })
diff --git a/server/helpers/video.ts b/server/helpers/video.ts
index d3445bed5..c2e15a705 100644
--- a/server/helpers/video.ts
+++ b/server/helpers/video.ts
@@ -4,7 +4,7 @@ import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/ty
4import { VideoPrivacy, VideoState } from '@shared/models' 4import { VideoPrivacy, VideoState } from '@shared/models'
5 5
6function getVideoWithAttributes (res: Response) { 6function getVideoWithAttributes (res: Response) {
7 return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights 7 return res.locals.videoAPI || res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights
8} 8}
9 9
10function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) { 10function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
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)
diff --git a/server/middlewares/validators/shared/videos.ts b/server/middlewares/validators/shared/videos.ts
index 3134f623d..1a22d6513 100644
--- a/server/middlewares/validators/shared/videos.ts
+++ b/server/middlewares/validators/shared/videos.ts
@@ -6,6 +6,7 @@ import {
6 MUser, 6 MUser,
7 MUserAccountId, 7 MUserAccountId,
8 MVideoAccountLight, 8 MVideoAccountLight,
9 MVideoFormattableDetails,
9 MVideoFullLight, 10 MVideoFullLight,
10 MVideoIdThumbnail, 11 MVideoIdThumbnail,
11 MVideoImmutable, 12 MVideoImmutable,
@@ -29,6 +30,10 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi
29 } 30 }
30 31
31 switch (fetchType) { 32 switch (fetchType) {
33 case 'for-api':
34 res.locals.videoAPI = video as MVideoFormattableDetails
35 break
36
32 case 'all': 37 case 'all':
33 res.locals.videoAll = video as MVideoFullLight 38 res.locals.videoAll = video as MVideoFullLight
34 break 39 break
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index 7f278c9f6..a707fd086 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
258} 258}
259 259
260const videosCustomGetValidator = ( 260const videosCustomGetValidator = (
261 fetchType: 'all' | 'only-video' | 'only-video-with-rights' | 'only-immutable-attributes', 261 fetchType: 'for-api' | 'all' | 'only-video' | 'only-video-with-rights' | 'only-immutable-attributes',
262 authenticateInQuery = false 262 authenticateInQuery = false
263) => { 263) => {
264 return [ 264 return [
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 9d56eb13c..00fbb18f6 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>>> {
1472 1472
1473 static loadForGetAPI (parameters: { 1473 static loadForGetAPI (parameters: {
1474 id: number | string 1474 id: number | string
1475 t?: Transaction 1475 transaction?: Transaction
1476 userId?: number 1476 userId?: number
1477 }): Promise<MVideoDetails> { 1477 }): Promise<MVideoDetails> {
1478 const { id, t, userId } = parameters 1478 const { id, transaction, userId } = parameters
1479 const queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize) 1479 const queryBuilder = new VideosModelGetQueryBuilder(VideoModel.sequelize)
1480 1480
1481 return queryBuilder.queryVideos({ id, transaction: t, forGetAPI: true, userId }) 1481 return queryBuilder.queryVideos({ id, transaction, forGetAPI: true, userId })
1482 } 1482 }
1483 1483
1484 static async getStats () { 1484 static async getStats () {
diff --git a/server/typings/express/index.d.ts b/server/typings/express/index.d.ts
index cbbf40a78..00ff68943 100644
--- a/server/typings/express/index.d.ts
+++ b/server/typings/express/index.d.ts
@@ -10,6 +10,7 @@ import {
10 MStreamingPlaylist, 10 MStreamingPlaylist,
11 MVideoChangeOwnershipFull, 11 MVideoChangeOwnershipFull,
12 MVideoFile, 12 MVideoFile,
13 MVideoFormattableDetails,
13 MVideoImmutable, 14 MVideoImmutable,
14 MVideoLive, 15 MVideoLive,
15 MVideoPlaylistFull, 16 MVideoPlaylistFull,
@@ -101,6 +102,7 @@ declare module 'express' {
101 locals: { 102 locals: {
102 docUrl?: string 103 docUrl?: string
103 104
105 videoAPI?: MVideoFormattableDetails
104 videoAll?: MVideoFullLight 106 videoAll?: MVideoFullLight
105 onlyImmutableVideo?: MVideoImmutable 107 onlyImmutableVideo?: MVideoImmutable
106 onlyVideo?: MVideoThumbnail 108 onlyVideo?: MVideoThumbnail