import { fetchVideo, VideoFetchType } from '../video'
import { UserRight } from '../../../shared/models/users'
import { VideoChannelModel } from '../../models/video/video-channel'
-import { MUser, MUserAccountId, MVideoAccountLight, MVideoFullLight, MVideoThumbnail, MVideoWithRights } from '@server/typings/models'
+import {
+ MUser,
+ MUserAccountId,
+ MVideoAccountLight,
+ MVideoFullLight,
+ MVideoIdThumbnail,
+ MVideoImmutable,
+ MVideoThumbnail,
+ MVideoWithRights
+} from '@server/typings/models'
+import { VideoFileModel } from '@server/models/video/video-file'
async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') {
const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
res.locals.videoAll = video as MVideoFullLight
break
+ case 'only-immutable-attributes':
+ res.locals.onlyImmutableVideo = video as MVideoImmutable
+ break
+
case 'id':
- res.locals.videoId = video
+ res.locals.videoId = video as MVideoIdThumbnail
break
case 'only-video':
return true
}
+async function doesVideoFileOfVideoExist (id: number, videoIdOrUUID: number | string, res: Response) {
+ if (!await VideoFileModel.doesVideoExistForVideoFile(id, videoIdOrUUID)) {
+ res.status(404)
+ .json({ error: 'VideoFile matching Video not found' })
+ .end()
+
+ return false
+ }
+
+ return true
+}
+
async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAccountId, res: Response) {
if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
export {
doesVideoChannelOfAccountExist,
doesVideoExist,
+ doesVideoFileOfVideoExist,
checkUserCanManageVideo
}