videosRouter.get('/:id',
openapiOperationDoc({ operationId: 'getVideo' }),
optionalAuthenticate,
- asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),
+ asyncMiddleware(videosCustomGetValidator('for-api')),
asyncMiddleware(checkVideoFollowConstraints),
asyncMiddleware(getVideo)
)
}
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.videoAPI
if (video.isOutdated()) {
JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })
import { 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) {
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>
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)
MUser,
MUserAccountId,
MVideoAccountLight,
+ MVideoFormattableDetails,
MVideoFullLight,
MVideoIdThumbnail,
MVideoImmutable,
}
switch (fetchType) {
+ case 'for-api':
+ res.locals.videoAPI = video as MVideoFormattableDetails
+ break
+
case 'all':
res.locals.videoAll = video as MVideoFullLight
break
}
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 [
static loadForGetAPI (parameters: {
id: number | string
- t?: Transaction
+ transaction?: Transaction
userId?: number
}): Promise<MVideoDetails> {
- const { id, t, userId } = parameters
+ const { id, transaction, userId } = parameters
const 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 () {
MStreamingPlaylist,
MVideoChangeOwnershipFull,
MVideoFile,
+ MVideoFormattableDetails,
MVideoImmutable,
MVideoLive,
MVideoPlaylistFull,
locals: {
docUrl?: string
+ videoAPI?: MVideoFormattableDetails
videoAll?: MVideoFullLight
onlyImmutableVideo?: MVideoImmutable
onlyVideo?: MVideoThumbnail