X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fshared%2Fvideos.ts;h=71b81654f582ab24d95828d134539173c2b1be46;hb=41fb13c330de629df2d23379209e79c7af0f2e9a;hp=a6dad4374bfa420bb3cb92a1b013c0d3e5ceb889;hpb=10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/shared/videos.ts b/server/middlewares/validators/shared/videos.ts index a6dad4374..71b81654f 100644 --- a/server/middlewares/validators/shared/videos.ts +++ b/server/middlewares/validators/shared/videos.ts @@ -1,24 +1,23 @@ import { Response } from 'express' -import { fetchVideo, VideoFetchType } from '@server/lib/model-loaders' +import { loadVideo, VideoLoadType } from '@server/lib/model-loaders' import { VideoChannelModel } from '@server/models/video/video-channel' import { VideoFileModel } from '@server/models/video/video-file' import { MUser, MUserAccountId, MVideoAccountLight, + MVideoFormattableDetails, MVideoFullLight, - MVideoIdThumbnail, + MVideoId, MVideoImmutable, - MVideoThumbnail, - MVideoWithRights + MVideoThumbnail } from '@server/types/models' -import { HttpStatusCode } from '@shared/core-utils' -import { UserRight } from '@shared/models' +import { HttpStatusCode, UserRight } from '@shared/models' -async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { +async function doesVideoExist (id: number | string, res: Response, fetchType: VideoLoadType = 'all') { const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined - const video = await fetchVideo(id, fetchType, userId) + const video = await loadVideo(id, fetchType, userId) if (video === null) { res.fail({ @@ -29,6 +28,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 MVideoFullLight break @@ -38,16 +41,12 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi break case 'id': - res.locals.videoId = video as MVideoIdThumbnail + res.locals.videoId = video as MVideoId break case 'only-video': res.locals.onlyVideo = video as MVideoThumbnail break - - case 'only-video-with-rights': - res.locals.onlyVideoWithRights = video as MVideoWithRights - break } return true