]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/middlewares/videos.ts
Add getSettings documentation
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / videos.ts
index 409f78650a63e24427c21e894b403320e46f4ee0..a0bbcdb21c0ceafa635f2e788b9cf4cf2674227c 100644 (file)
@@ -12,6 +12,7 @@ import {
   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
@@ -51,6 +52,18 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi
   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)
@@ -107,5 +120,6 @@ function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right:
 export {
   doesVideoChannelOfAccountExist,
   doesVideoExist,
+  doesVideoFileOfVideoExist,
   checkUserCanManageVideo
 }