Add downloadingEnabled property to video model
[oweals/peertube.git] / server / helpers / custom-validators / videos.ts
index c9ef8445d2a69cd1934df579a8e7a24c5062ce83..714f7ac956c25b8dcc35f02b716830430a131e10 100644 (file)
@@ -18,6 +18,7 @@ import { exists, isArray, isFileValid } from './misc'
 import { VideoChannelModel } from '../../models/video/video-channel'
 import { UserModel } from '../../models/account/user'
 import * as magnetUtil from 'magnet-uri'
+import { fetchVideo, VideoFetchType } from '../video'
 
 const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
 
@@ -152,17 +153,10 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use
   return true
 }
 
-export type VideoFetchType = 'all' | 'only-video' | 'id' | 'none'
 async function isVideoExist (id: string, res: Response, fetchType: VideoFetchType = 'all') {
-  let video: VideoModel | null
-
-  if (fetchType === 'all') {
-    video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id)
-  } else if (fetchType === 'only-video') {
-    video = await VideoModel.load(id)
-  } else if (fetchType === 'id' || fetchType === 'none') {
-    video = await VideoModel.loadOnlyId(id)
-  }
+  const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
+
+  const video = await fetchVideo(id, fetchType, userId)
 
   if (video === null) {
     res.status(404)